我有一个带有操作按钮的应用栏的外部脚手架,单击该按钮时我想将内部 Stateful 小部件的状态保存到 perm 存储 - 能够从外部应用栏调用内部小部件方法的最佳方法是什么并且还可以在被调用的方法中执行 Scaffold.of(context) 吗?
class AISSettings extends StatelessWidget {
static const String route = 'settings/ais';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('AIS settings'),
actions: <Widget>[
IconButton(icon: Icon(Icons.check), onPressed: () => {/* call _SettingsState.saveStuff() */} ),
],
),
bottomNavigationBar: Navbar(),
body: AISSettingsForm(),
);
}
}
class AISSettingsForm extends StatefulWidget {
@override
_SettingsState createState() => _SettingsState();
}
class _SettingsState extends State<AISSettingsForm> {
final _formKey = GlobalKey<_SettingsState>();
Map<String, dynamic> _options;
saveStuff() {
// Scaffold.of(context).showSnackBar(....)
}
}