iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 11
0

目前檔案架構
https://ithelp.ithome.com.tw/upload/images/20181008/20111840tioAaZBwTd.png

  1. pages/products.dart
import './products_admin.dart';
...
    return Scaffold(
      drawer: Drawer(
        child: Column(
          children: <Widget>[
            AppBar(
              automaticallyImplyLeading: false,
              title: Text('Choose'),
            ),
            ListTile(
              title: Text('Manage Products'),
              onTap: () {
                Navigator.pushReplacement(
                    context,
                    MaterialPageRoute(
                        builder: (BuildContext context) => ProductsAdminPage()
                        //按下去以後切到ProductsAdminPage頁面
                    )
                );
              },
            )
          ],
        ),
      ),
  1. pages/products_admin.dart
import 'package:flutter/material.dart';

import './products.dart';
import './product_create.dart';
import './product_list.dart';

class ProductsAdminPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
    //有tab的組件最外層
      length: 2,
      //兩個tab
      child: Scaffold(
        drawer: Drawer(
          //這一頁的收合選單是切換回products.dart
          child: Column(
            children: <Widget>[
              AppBar(
                automaticallyImplyLeading: false,
                title: Text('Choose'),
              ),
              ListTile(
                title: Text('All Products'),
                onTap: () {
                  Navigator.pushReplacement(
                      context,
                      MaterialPageRoute(
                          builder: (BuildContext context) => ProductsPage()));
                },
              )
            ],
          ),
        ),
        appBar: AppBar(
          title: Text('Manage Products'),
          bottom: TabBar(
          //把tab放在bottom屬性裡面
            tabs: <Widget>[
              Tab(
                icon: Icon(Icons.create),
                text: 'Create Product',
              ),
              Tab(
                icon: Icon(Icons.list),
                text: 'My Products',
              ),
            ],
          ),
        ),
        body: TabBarView(
          children: <Widget>[ProductCreatePage(), ProductListPage()],
          //對應上面的順序,切換的頁面
        ),
      ),
    );
  }
}

  1. pages/product_create.dart
import 'package:flutter/material.dart';

class ProductCreatePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(child: Text('Create a Product'),);
  }
}
  1. pages/product_list.dart
import 'package:flutter/material.dart';

class ProductListPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text('All Products'),
    );
  }
}

https://i.imgur.com/2qgDrB2.gif


主題來源:
Learn Flutter & Dart to Build iOS & Android Apps


上一篇
收合式選單
下一篇
使用名稱管理route,並移動state到main.dart
系列文
使用flutter建構Android和iOs APP25
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言