123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- // Copyright 2019 The Flutter team. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- import 'package:flutter/material.dart';
- import 'package:ustest/TestCaseView.dart';
- import 'package:ustest/UserView.dart';
- class MainScreen extends StatefulWidget {
- const MainScreen({Key? key}) : super(key: key);
- @override
- _MainScreenState createState() => _MainScreenState();
- }
- class _MainScreenState extends State<MainScreen> with RestorationMixin {
- final RestorableInt _selectedIndex = RestorableInt(0);
- @override
- String get restorationId => 'nav_rail_demo';
- @override
- void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
- registerForRestoration(_selectedIndex, 'selected_index');
- }
- @override
- void dispose() {
- _selectedIndex.dispose();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- print("build MainScreen");
- final selectedItem = <Widget>[UserView(), TestCaseView()];
- return Scaffold(
- appBar: AppBar(
- title: Text(
- "demoNavigationRailTitle",
- ),
- ),
- body: Row(
- children: [
- NavigationRail(
- selectedIndex: _selectedIndex.value,
- onDestinationSelected: (index) {
- setState(() {
- var oldIndex = _selectedIndex.value;
- print('oldIndex:$oldIndex =>index:$index');
- _selectedIndex.value = index;
- });
- },
- labelType: NavigationRailLabelType.selected,
- destinations: [
- NavigationRailDestination(
- icon: const Icon(
- Icons.account_circle_outlined,
- ),
- selectedIcon: const Icon(
- Icons.account_circle_rounded,
- ),
- label: Text(
- "客戶端",
- ),
- ),
- NavigationRailDestination(
- icon: const Icon(
- Icons.folder,
- ),
- selectedIcon: const Icon(
- Icons.folder_rounded,
- ),
- label: Text(
- "TODO",
- ),
- ),
- ],
- ),
- const VerticalDivider(thickness: 1, width: 1),
- Expanded(
- child: Center(
- child: selectedItem[_selectedIndex.value],
- ),
- ),
- ],
- ),
- );
- }
- }
|