MainScreen.dart 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2019 The Flutter team. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. import 'package:flutter/material.dart';
  5. import 'package:ustest/TestCaseView.dart';
  6. import 'package:ustest/UserView.dart';
  7. class MainScreen extends StatefulWidget {
  8. const MainScreen({Key? key}) : super(key: key);
  9. @override
  10. _MainScreenState createState() => _MainScreenState();
  11. }
  12. class _MainScreenState extends State<MainScreen> with RestorationMixin {
  13. final RestorableInt _selectedIndex = RestorableInt(0);
  14. @override
  15. String get restorationId => 'nav_rail_demo';
  16. @override
  17. void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
  18. registerForRestoration(_selectedIndex, 'selected_index');
  19. }
  20. @override
  21. void dispose() {
  22. _selectedIndex.dispose();
  23. super.dispose();
  24. }
  25. @override
  26. Widget build(BuildContext context) {
  27. print("build MainScreen");
  28. final selectedItem = <Widget>[UserView(), TestCaseView()];
  29. return Scaffold(
  30. appBar: AppBar(
  31. title: Text(
  32. "demoNavigationRailTitle",
  33. ),
  34. ),
  35. body: Row(
  36. children: [
  37. NavigationRail(
  38. selectedIndex: _selectedIndex.value,
  39. onDestinationSelected: (index) {
  40. setState(() {
  41. var oldIndex = _selectedIndex.value;
  42. print('oldIndex:$oldIndex =>index:$index');
  43. _selectedIndex.value = index;
  44. });
  45. },
  46. labelType: NavigationRailLabelType.selected,
  47. destinations: [
  48. NavigationRailDestination(
  49. icon: const Icon(
  50. Icons.account_circle_outlined,
  51. ),
  52. selectedIcon: const Icon(
  53. Icons.account_circle_rounded,
  54. ),
  55. label: Text(
  56. "客戶端",
  57. ),
  58. ),
  59. NavigationRailDestination(
  60. icon: const Icon(
  61. Icons.folder,
  62. ),
  63. selectedIcon: const Icon(
  64. Icons.folder_rounded,
  65. ),
  66. label: Text(
  67. "TODO",
  68. ),
  69. ),
  70. ],
  71. ),
  72. const VerticalDivider(thickness: 1, width: 1),
  73. Expanded(
  74. child: Center(
  75. child: selectedItem[_selectedIndex.value],
  76. ),
  77. ),
  78. ],
  79. ),
  80. );
  81. }
  82. }