1. 程式人生 > >Flutter - Error: 'xxx' is imported from both package...

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

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_alert fluttertoast中,編譯器不確定到底是引用的哪一個包中的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 );

 

 

 

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