2023-09-02 21:29:06 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'about_page.dart';
|
|
|
|
import 'timers_page.dart';
|
|
|
|
import 'settings_page.dart';
|
|
|
|
|
|
|
|
import 'constants.dart';
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
|
|
const MyHomePage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
|
|
|
|
|
|
|
|
var selectedIndex = 0;
|
|
|
|
late TabController _tabController;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_tabController = TabController(length: 3, vsync: this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_tabController.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _handleTabSelection(int index) {
|
|
|
|
setState(() {
|
|
|
|
selectedIndex = _tabController.index = index;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-09-05 22:47:13 +08:00
|
|
|
static const List<Widget> pages = [
|
|
|
|
TimersPage(),
|
|
|
|
AboutPage(),
|
|
|
|
SettingsPage(),
|
|
|
|
];
|
|
|
|
|
2023-09-02 21:29:06 +08:00
|
|
|
Widget getPage(int selectedIndex) {
|
|
|
|
Widget page;
|
|
|
|
|
|
|
|
switch (selectedIndex) {
|
|
|
|
case 0:
|
|
|
|
page = const TimersPage();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
page = const AboutPage();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
page = const SettingsPage();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw UnimplementedError('no widget for $selectedIndex');
|
|
|
|
}
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
2023-09-29 19:58:06 +08:00
|
|
|
static List<NavigationRailDestination> navRailDestinations = [
|
|
|
|
const NavigationRailDestination(
|
|
|
|
icon: Icon(Icons.timer_outlined),
|
|
|
|
selectedIcon: Icon(Icons.timer),
|
|
|
|
label: Text('Timers'),
|
|
|
|
),
|
|
|
|
const NavigationRailDestination(
|
|
|
|
icon: Icon(Icons.access_time),
|
|
|
|
selectedIcon: Icon(Icons.access_time_filled),
|
|
|
|
label: Text('Alarms'),
|
|
|
|
),
|
|
|
|
const NavigationRailDestination(
|
|
|
|
icon: Icon(Icons.settings_outlined),
|
|
|
|
selectedIcon: Icon(Icons.settings),
|
|
|
|
label: Text('Settings'),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2023-09-02 21:29:06 +08:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
centerTitle: true,
|
|
|
|
toolbarHeight: 0,
|
|
|
|
bottom: (MediaQuery.of(context).size.width > 600)
|
|
|
|
? null
|
|
|
|
: TabBar(
|
|
|
|
indicatorSize: TabBarIndicatorSize.tab,
|
2023-09-29 19:58:06 +08:00
|
|
|
isScrollable: false, // If true, the tabbar cannot be center aligned
|
2023-09-02 21:29:06 +08:00
|
|
|
controller: _tabController,
|
|
|
|
onTap: _handleTabSelection,
|
|
|
|
tabs: const <Widget>[
|
|
|
|
Tab(text: 'Timers'),
|
|
|
|
Tab(text: 'Alarms'),
|
|
|
|
Tab(text: 'Settings'),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
body: (MediaQuery.of(context).size.width > 600)
|
|
|
|
? LayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
|
|
|
return Scaffold(
|
|
|
|
body: Row(
|
|
|
|
children: [
|
|
|
|
SafeArea(
|
|
|
|
child: NavigationRail(
|
|
|
|
extended: constraints.maxWidth >= 900,
|
|
|
|
selectedIndex: _tabController.index,
|
|
|
|
onDestinationSelected: (value) {
|
|
|
|
setState(() {
|
|
|
|
selectedIndex = value;
|
|
|
|
_tabController.index = value;
|
|
|
|
});
|
|
|
|
},
|
2023-09-29 19:58:06 +08:00
|
|
|
destinations: navRailDestinations,
|
2023-09-02 21:29:06 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: myBorderRadius, // 设置圆角程度
|
|
|
|
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.3), // 设置 Container 的背景颜色
|
|
|
|
),
|
|
|
|
child: getPage(_tabController.index),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
)
|
|
|
|
: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: myBorderRadius,
|
|
|
|
color: Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.3),
|
|
|
|
),
|
|
|
|
child: TabBarView(
|
|
|
|
controller: _tabController,
|
2023-09-05 22:47:13 +08:00
|
|
|
children: pages,
|
2023-09-02 21:29:06 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|