MainScreen.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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:colorize_logger/colorize_logger.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:get_it/get_it.dart';
  7. import 'package:ustest/AutoTestView.dart';
  8. import 'package:ustest/MyView.dart';
  9. import 'package:ustest/PackageView.dart';
  10. import 'package:ustest/PublishView.dart';
  11. import 'BuildView.dart';
  12. import 'Services/UserService.dart';
  13. import 'package:flutter_gen/gen_l10n/app_localizations.dart';
  14. class MainScreen extends StatefulWidget {
  15. const MainScreen({Key? key}) : super(key: key);
  16. @override
  17. _MainScreenState createState() => _MainScreenState();
  18. }
  19. class _MainScreenState extends State<MainScreen> with RestorationMixin {
  20. final RestorableInt _selectedIndex = RestorableInt(0);
  21. @override
  22. String get restorationId => 'nav_rail_demo';
  23. @override
  24. void restoreState(RestorationBucket? oldBucket, bool initialRestore) {
  25. registerForRestoration(_selectedIndex, 'selected_index');
  26. }
  27. @override
  28. void initState() {
  29. Logger.info('MainScreen initState');
  30. super.initState();
  31. }
  32. void loadUserData() async {
  33. try {
  34. var service = GetIt.instance.get<UserService>();
  35. await service.UpdateCurrentUserDetail();
  36. } catch (ex) {
  37. Logger.warning('loadUserData ex:$ex');
  38. }
  39. }
  40. @override
  41. void dispose() {
  42. _selectedIndex.dispose();
  43. Logger.info('MainScreen dispose');
  44. super.dispose();
  45. }
  46. @override
  47. Widget build(BuildContext context) {
  48. print("build MainScreen");
  49. final selectedItem = <Widget>[
  50. BuildView(),
  51. PackageView(),
  52. PublishView(),
  53. AutoTestView(),
  54. MyView()
  55. ]; //DOTo
  56. return Scaffold(
  57. appBar: AppBar(
  58. title: Text(
  59. AppLocalizations.of(context)!.deploySystem,
  60. ),
  61. ),
  62. body: Row(
  63. children: [
  64. NavigationRail(
  65. selectedIndex: _selectedIndex.value,
  66. onDestinationSelected: (index) {
  67. setState(() {
  68. var oldIndex = _selectedIndex.value;
  69. print('oldIndex:$oldIndex =>index:$index');
  70. _selectedIndex.value = index;
  71. });
  72. },
  73. labelType: NavigationRailLabelType.all,
  74. destinations: [
  75. NavigationRailDestination(
  76. icon: const Icon(
  77. Icons.build_outlined,
  78. ),
  79. selectedIcon: const Icon(
  80. Icons.build_rounded,
  81. ),
  82. label: Text(
  83. AppLocalizations.of(context)!.build,
  84. ),
  85. ),
  86. NavigationRailDestination(
  87. icon: const Icon(
  88. Icons.badge_outlined,
  89. ),
  90. selectedIcon: const Icon(
  91. Icons.badge_rounded,
  92. ),
  93. label: Text(
  94. AppLocalizations.of(context)!.package,
  95. ),
  96. ),
  97. NavigationRailDestination(
  98. icon: const Icon(
  99. Icons.publish_outlined,
  100. ),
  101. selectedIcon: const Icon(
  102. Icons.publish_rounded,
  103. ),
  104. label: Text(
  105. AppLocalizations.of(context)!.publish,
  106. ),
  107. ),
  108. NavigationRailDestination(
  109. icon: const Icon(
  110. Icons.list_outlined,
  111. ),
  112. selectedIcon: const Icon(
  113. Icons.list_alt_rounded,
  114. ),
  115. label: Text(
  116. AppLocalizations.of(context)!.autoTest,
  117. ),
  118. ),
  119. NavigationRailDestination(
  120. icon: const Icon(
  121. Icons.account_circle_outlined,
  122. ),
  123. selectedIcon: const Icon(
  124. Icons.account_circle_rounded,
  125. ),
  126. label: Text(
  127. "My",
  128. ),
  129. ),
  130. ],
  131. ),
  132. const VerticalDivider(thickness: 1, width: 1),
  133. Expanded(
  134. child: Center(
  135. child: selectedItem[_selectedIndex.value],
  136. ),
  137. ),
  138. ],
  139. ),
  140. );
  141. }
  142. }