首页 > 解决方案 > 在 Flutter 中,我想在导航到新屏幕后立即调用 for 循环。我把代码放在哪里?

问题描述

基本上我只想在推送到新屏幕后立即调用一些代码。我会把我的代码放在哪里?

标签: dartflutter

解决方案


你可以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),            
     ),            
   ),            
 );

推荐阅读