:::

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');
          },
        ),
      ),
    );

     


:::

書籍目錄

展開 | 闔起

快速登入


http%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1894%26tbsn%3D42

計數器

今天: 638638638
昨天: 3068306830683068
總計: 8077143807714380771438077143807714380771438077143