index_page.dart 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_clock/pages/alarm_page.dart';
  3. import 'package:flutter_clock/pages/clock_page.dart';
  4. import 'package:flutter_clock/pages/stopwatch_page.dart';
  5. import 'package:flutter_clock/pages/timer/timer_page.dart';
  6. import 'package:flutter_screenutil/flutter_screenutil.dart';
  7. /// Description: main page
  8. /// Time : 04/06/2025 Sunday
  9. /// Author : liuyuqi.gov@msn.cn
  10. class IndexPage extends StatefulWidget {
  11. @override
  12. State<StatefulWidget> createState() {
  13. return _IndexPageState();
  14. }
  15. }
  16. class _IndexPageState extends State<IndexPage>
  17. with SingleTickerProviderStateMixin {
  18. late TabController _tabController;
  19. late List<Widget> _tabs;
  20. @override
  21. void initState() {
  22. super.initState();
  23. _tabController = TabController(
  24. length: 4,
  25. vsync: this,
  26. initialIndex: 3); // Timer tab is selected by default
  27. // Initialize tabs with screen adaptation
  28. _tabs = [
  29. Tab(child: Text('Alarm', style: TextStyle(fontSize: 16.sp))),
  30. Tab(child: Text('Clock', style: TextStyle(fontSize: 16.sp))),
  31. Tab(child: Text('Stopwatch', style: TextStyle(fontSize: 16.sp))),
  32. Tab(child: Text('Timer', style: TextStyle(fontSize: 16.sp))),
  33. ];
  34. }
  35. @override
  36. void dispose() {
  37. _tabController.dispose();
  38. super.dispose();
  39. }
  40. @override
  41. Widget build(BuildContext context) {
  42. return Scaffold(
  43. appBar: AppBar(
  44. backgroundColor: Colors.white,
  45. elevation: 0,
  46. toolbarHeight: 50.h,
  47. title: TabBar(
  48. controller: _tabController,
  49. tabs: _tabs,
  50. labelColor: Colors.blue,
  51. unselectedLabelColor: Colors.black,
  52. indicatorColor: Colors.blue,
  53. indicatorWeight: 3.h,
  54. ),
  55. // actions: [
  56. // IconButton(
  57. // icon: Icon(Icons.more_vert, color: Colors.black),
  58. // onPressed: () {
  59. // // More options menu
  60. // },
  61. // ),
  62. // ],
  63. ),
  64. body: TabBarView(
  65. controller: _tabController,
  66. children: [
  67. AlarmPage(),
  68. ClockPage(),
  69. StopwatchPage(),
  70. TimerPage(),
  71. ],
  72. ),
  73. );
  74. }
  75. }