Flutter - Error: 'xxx' is imported from both package...

时间:2024-07-01 09:03:38
Compiler message:
lib/main.dart:77:32: Error: 'Toast' is imported from both
'package:easy_alert/src/provider.dart' and
'package:fluttertoast/fluttertoast.dart'.
toastLength: Toast.LENGTH_LONG);

由于引用的"Toast"同时存在于package  easy_alertfluttertoast中,编译器不确定到底是引用的哪一个包中的Toast,因此报错。

解决方法:

import 'package:easy_alert/easy_alert.dart' as easyAlertV;
import 'package:fluttertoast/fluttertoast.dart' as flutterToastV;

然后

flutterToastV.Fluttertoast.showToast(msg: "数据存储成功",
toastLength: flutterToastV.Toast.LENGTH_SHORT,
gravity: flutterToastV.ToastGravity.BOTTOM,
timeInSecForIos: 1
);

原文参考我的* https://*.com/questions/53359139/error-toast-is-imported-from-both-packageeasy-alert-src-provider-dart-and