|
@@ -1,4 +1,3 @@
|
|
-
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_clock/pages/alarm_page.dart';
|
|
import 'package:flutter_clock/pages/alarm_page.dart';
|
|
import 'package:flutter_clock/pages/clock_page.dart';
|
|
import 'package:flutter_clock/pages/clock_page.dart';
|
|
@@ -32,10 +31,10 @@ class _IndexPageState extends State<IndexPage>
|
|
|
|
|
|
// Initialize tabs with screen adaptation
|
|
// Initialize tabs with screen adaptation
|
|
_tabs = [
|
|
_tabs = [
|
|
- Tab(child: Text('Alarm', style: TextStyle(fontSize: 16.sp, color: Colors.black))),
|
|
|
|
- Tab(child: Text('Clock', style: TextStyle(fontSize: 16.sp, color: Colors.black))),
|
|
|
|
- Tab(child: Text('Stopwatch', style: TextStyle(fontSize: 16.sp, color: Colors.black))),
|
|
|
|
- Tab(child: Text('Timer', style: TextStyle(fontSize: 16.sp, color: Colors.black))),
|
|
|
|
|
|
+ Tab(child: Text('Alarm', style: TextStyle(fontSize: 16.sp))),
|
|
|
|
+ Tab(child: Text('Clock', style: TextStyle(fontSize: 16.sp))),
|
|
|
|
+ Tab(child: Text('Stopwatch', style: TextStyle(fontSize: 16.sp))),
|
|
|
|
+ Tab(child: Text('Timer', style: TextStyle(fontSize: 16.sp))),
|
|
];
|
|
];
|
|
|
|
|
|
}
|
|
}
|
|
@@ -60,6 +59,8 @@ class _IndexPageState extends State<IndexPage>
|
|
unselectedLabelColor: Colors.black,
|
|
unselectedLabelColor: Colors.black,
|
|
indicatorColor: Colors.blue,
|
|
indicatorColor: Colors.blue,
|
|
indicatorWeight: 3.h,
|
|
indicatorWeight: 3.h,
|
|
|
|
+ labelStyle: TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
+ unselectedLabelStyle: TextStyle(fontWeight: FontWeight.normal),
|
|
),
|
|
),
|
|
// actions: [
|
|
// actions: [
|
|
// IconButton(
|
|
// IconButton(
|
|
@@ -74,14 +75,34 @@ class _IndexPageState extends State<IndexPage>
|
|
body: TabBarView(
|
|
body: TabBarView(
|
|
controller: _tabController,
|
|
controller: _tabController,
|
|
children: [
|
|
children: [
|
|
- AlarmPage(),
|
|
|
|
- ClockPage(),
|
|
|
|
- StopwatchPage(),
|
|
|
|
- TimerPage(),
|
|
|
|
|
|
+ // Wrap each page with AutomaticKeepAlive widget to preserve state
|
|
|
|
+ KeepAlivePage(child: AlarmPage()),
|
|
|
|
+ KeepAlivePage(child: ClockPage()),
|
|
|
|
+ KeepAlivePage(child: StopwatchPage()),
|
|
|
|
+ KeepAlivePage(child: TimerPage()),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/// A wrapper widget that keeps its child alive when switching between tabs
|
|
|
|
+class KeepAlivePage extends StatefulWidget {
|
|
|
|
+ final Widget child;
|
|
|
|
|
|
|
|
+ const KeepAlivePage({Key? key, required this.child}) : super(key: key);
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ _KeepAlivePageState createState() => _KeepAlivePageState();
|
|
|
|
+}
|
|
|
|
|
|
|
|
+class _KeepAlivePageState extends State<KeepAlivePage> with AutomaticKeepAliveClientMixin {
|
|
|
|
+ @override
|
|
|
|
+ bool get wantKeepAlive => true;
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ Widget build(BuildContext context) {
|
|
|
|
+ super.build(context); // Important: This must be called
|
|
|
|
+ return widget.child;
|
|
|
|
+ }
|
|
}
|
|
}
|