74 lines
1.9 KiB
Dart
74 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/foundation.dart' show kIsWeb;
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'today_screen.dart';
|
|
import 'stats_screen.dart';
|
|
import 'settings_screen.dart';
|
|
import '../providers/background_sync_provider.dart';
|
|
|
|
class HomeScreen extends ConsumerStatefulWidget {
|
|
const HomeScreen({super.key});
|
|
|
|
@override
|
|
ConsumerState<HomeScreen> createState() => _HomeScreenState();
|
|
}
|
|
|
|
class _HomeScreenState extends ConsumerState<HomeScreen> {
|
|
int _currentIndex = 0;
|
|
|
|
final List<Widget> _screens = [
|
|
const TodayScreen(),
|
|
const StatsScreen(),
|
|
const SettingsScreen(),
|
|
];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// Web 平台不启动后台同步服务
|
|
if (!kIsWeb) {
|
|
// 启动后台同步服务
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
final syncService = ref.read(backgroundSyncServiceProvider);
|
|
syncService.start();
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: IndexedStack(
|
|
index: _currentIndex,
|
|
children: _screens,
|
|
),
|
|
bottomNavigationBar: NavigationBar(
|
|
selectedIndex: _currentIndex,
|
|
onDestinationSelected: (index) {
|
|
setState(() {
|
|
_currentIndex = index;
|
|
});
|
|
},
|
|
destinations: const [
|
|
NavigationDestination(
|
|
icon: Icon(Icons.today_outlined),
|
|
selectedIcon: Icon(Icons.today),
|
|
label: 'Today',
|
|
),
|
|
NavigationDestination(
|
|
icon: Icon(Icons.bar_chart_outlined),
|
|
selectedIcon: Icon(Icons.bar_chart),
|
|
label: 'Stats',
|
|
),
|
|
NavigationDestination(
|
|
icon: Icon(Icons.settings_outlined),
|
|
selectedIcon: Icon(Icons.settings),
|
|
label: 'Settings',
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|