:::

6-7 用路由切換頁面

  1. 先在入口處設定路由
    MaterialApp(
      // home: HomePage(),
      initialRoute: '/',
      routes: {
        '/': (BuildContext context) => HomePage(),
        '/Page2': (BuildContext context) => Page2(),
      },
    ),

     

  2. 使用路由
    GestureDetector(
      onTap: () {
        NavigatorState nav = Navigator.of(context);
        nav.pushNamed('/Page2');
      },
      child: buildImageView(urls[index], align: positions[index]),
    );

     

  3. 按回上頁按鈕要能回到原本頁面:
    return Scaffold(
      appBar: AppBar(
        leading: BackButton(
          onPressed: () {
            Navigator.of(context).pop('來自 Page2');
          },
        ),
      ),
    );

     


:::

書籍目錄

展開 | 闔起

https%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D42%26tbdsn%3D1894

計數器

今天: 3438343834383438
昨天: 4771477147714771
總計: 5539441553944155394415539441553944155394415539441