Pet*_*all 5 widget dart flutter
我已经为 WillPopScope 创建了一个自定义小部件(如下),你如何初始化 WillPopCallback onWillPop?
我收到警告说 onWillPop 变量没有初始化,也没有找到应该如何初始化。
在 PlatformWillPopScope 的以下实现中,WillPopCallback onWillPop 只是传递给 Flutter 定义的小部件 WillPopScope。从 Dart 分析窗口中,我收到以下错误:
warning: The final variable 'onWillPop' must be initialized. (final_not_initialized_constructor_1 at [draw_navigation_app] lib/common/platform/platformWillPopScope.dart:15)
Run Code Online (Sandbox Code Playgroud)
我只是想将 onWillPop 初始化为任何值,因为实际值将从构造函数提供。
class PlatformWillPopScope extends StatelessWidget{
final Key key;
final Widget child;
final WillPopCallback onWillPop;
final EdgeInsetsGeometry paddingExternal = EdgeInsets.all(0.0);
PlatformWillPopScope({
this.key,
this.child,
onWillPop
}) : assert(child != null),
super(key: key);
@override
Widget build(BuildContext context) {
return Platform.isIOS ?
Padding(padding: paddingExternal == null ? EdgeInsets.all(0.0) :
paddingExternal,
child: child,
)
:
WillPopScope(key: key,
child: child,
onWillPop: onWillPop);
}
}
Run Code Online (Sandbox Code Playgroud)
感谢塞巴斯蒂安,它让我找到了答案。
final WillPopCallback onWillPop = () {return Future.value(false);};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2821 次 |
最近记录: |