问题描述
运行Flutter应用程序时出现问题。 我有一个使用包Share的_GoldProductPageState类。
Error: The getter 'Share' isn't defined for the class '_GoldProductPageState'.
'_GoldProductPageState' is from 'package:tanamduit/View/Pages/gold/GoldProductPage.dart' ('lib/View/Pages/gold/GoldProductPage.dart').
Try correcting the name to the name of an existing getter,or defining a getter or field named 'Share'. onPressed: () => Share.share(uri.toString()),
这是我在GoldProductPage.dart中使用共享软件包的代码:
GestureDetector(
child: Container(
height: 50,width: 100,child: FutureBuilder<Uri>(
future: _dynamicLinkService.createDynamicLink(),builder: (context,snapshot) {
if(snapshot.hasData) {
Uri uri = snapshot.data;
return FloatingActionButton(
backgroundColor: Colors.amber,onPressed: () => Share.share(uri.toString()),child: Text('Share'),);
} else {
return Container();
}
}
),),
这是类'_GoldProductPageState'的代码:
class _GoldProductPageState extends State<GoldProductPage> {
final BaseDynamicLinks _dynamicLinkService = BaseDynamicLinks();
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {
Navigator.of(context).pop();
return;
},
这是pubspec.yaml:
responsive_widgets: ^2.0.1
flutter_screenutil: ^1.0.2
toggle_switch: "^0.1.4"
font_awesome_flutter: ^8.8.1
share: ^0.6.4+3
dev_dependencies:
test: ^1.5.1
flutter_test:
sdk: flutter
您可以在此处查看我的完整代码: https://pastebin.com/5ry5i7et
我怎么了? 谢谢
解决方法
尝试
onPressed: ()
{
Share.share(uri.toString());
},