// 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:colorize_logger/colorize_logger.dart'; import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; import 'package:ustest/AutoTestView.dart'; import 'package:ustest/MyView.dart'; import 'package:ustest/PackageView.dart'; import 'package:ustest/PublishView.dart'; import 'BuildView.dart'; import 'Services/UserService.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class MainScreen extends StatefulWidget { const MainScreen({Key? key}) : super(key: key); @override _MainScreenState createState() => _MainScreenState(); } class _MainScreenState extends State 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 initState() { Logger.info('MainScreen initState'); super.initState(); } void loadUserData() async { try { var service = GetIt.instance.get(); await service.UpdateCurrentUserDetail(); } catch (ex) { Logger.warning('loadUserData ex:$ex'); } } @override void dispose() { _selectedIndex.dispose(); Logger.info('MainScreen dispose'); super.dispose(); } @override Widget build(BuildContext context) { print("build MainScreen"); final selectedItem = [ BuildView(), PackageView(), PublishView(), AutoTestView(), MyView() ]; //DOTo return Scaffold( appBar: AppBar( title: Text( AppLocalizations.of(context)!.deploySystem, ), ), body: Row( children: [ NavigationRail( selectedIndex: _selectedIndex.value, onDestinationSelected: (index) { setState(() { var oldIndex = _selectedIndex.value; print('oldIndex:$oldIndex =>index:$index'); _selectedIndex.value = index; }); }, labelType: NavigationRailLabelType.all, destinations: [ NavigationRailDestination( icon: const Icon( Icons.build_outlined, ), selectedIcon: const Icon( Icons.build_rounded, ), label: Text( AppLocalizations.of(context)!.build, ), ), NavigationRailDestination( icon: const Icon( Icons.badge_outlined, ), selectedIcon: const Icon( Icons.badge_rounded, ), label: Text( AppLocalizations.of(context)!.package, ), ), NavigationRailDestination( icon: const Icon( Icons.publish_outlined, ), selectedIcon: const Icon( Icons.publish_rounded, ), label: Text( AppLocalizations.of(context)!.publish, ), ), NavigationRailDestination( icon: const Icon( Icons.list_outlined, ), selectedIcon: const Icon( Icons.list_alt_rounded, ), label: Text( AppLocalizations.of(context)!.autoTest, ), ), NavigationRailDestination( icon: const Icon( Icons.account_circle_outlined, ), selectedIcon: const Icon( Icons.account_circle_rounded, ), label: Text( "My", ), ), ], ), const VerticalDivider(thickness: 1, width: 1), Expanded( child: Center( child: selectedItem[_selectedIndex.value], ), ), ], ), ); } }