:::
6-7 用路由切換頁面
- 先在入口處設定路由
MaterialApp( // home: HomePage(), initialRoute: '/', routes: { '/': (BuildContext context) => HomePage(), '/Page2': (BuildContext context) => Page2(), }, ), - 使用路由
GestureDetector( onTap: () { NavigatorState nav = Navigator.of(context); nav.pushNamed('/Page2'); }, child: buildImageView(urls[index], align: positions[index]), ); - 按回上頁按鈕要能回到原本頁面:
return Scaffold( appBar: AppBar( leading: BackButton( onPressed: () { Navigator.of(context).pop('來自 Page2'); }, ), ), );
6-6 點擊跳出對話框