基本上,我只是想在推送到新屏幕后立即调用一些代码。我将代码放在哪里?
答案 0 :(得分:2)
您可以通过新屏幕小部件的build
方法执行此操作。
flutter.io中的示例:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// instead of the next statement, place your code that you want to execute
final wordPair = WordPair.random();
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
title: Text('Welcome to Flutter'),
),
body: Center(
child: Text('Hello World'),
child: Text(wordPair.asPascalCase),
),
),
);