【发布时间】:2021-04-12 07:20:45
【问题描述】:
提前谢谢....
我有一个使用 Flutter 构建的应用程序,其中 main.dart 文件具有 void 功能。我有另一个带有凸起按钮的 dart 文件,我想从 main.dart 文件中调用 void 函数
这可能吗??
//This is the void in the main.dart file
void buildBottomSheet(double height, MedicineModel model) async {
var medicineId = await showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(45), topRight: Radius.circular(45))),
context: context,
isScrollControlled: true,
builder: (context) {
return FadeAnimation(
.6,
AddMedicine(height, model.getDatabase(),
model.notificationManager),
);
});
if (medicineId != null) {
Fluttertoast.showToast(
msg: "Reminder Added!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM_LEFT,
timeInSecForIosWeb: 1,
backgroundColor: Theme
.of(context)
.accentColor,
textColor: Colors.white,
fontSize: 20.0);
setState(() {});
}
} //and then a raised button in a different .dart file to call this void?
【问题讨论】:
-
你能给我们看一个代码示例吗?
-
感谢沼泽摆动
-
您有任何错误吗?我觉得你应该没问题。只需将 main.dart 导入到 RaisedButton 所在的任何文件中
-
嗨何塞·乔治,谢谢。但是,是的,错误是存在的。我已经导入 main.dart 但它仍然说 buildBottomSheet 没有为 MyApp 类型定义
标签: function flutter call void