Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
page_navigator.dart
Go to the documentation of this file.
1import 'package:flutter/material.dart';
2import 'package:flutter_screenutil/flutter_screenutil.dart';
3import 'package:hugeicons/hugeicons.dart';
4
5class PageNavigator extends StatefulWidget {
7 super.key,
8 required this.tottalPages,
9 required this.currentPage,
10 required this.pageController,
11 });
12
13 final int tottalPages;
14 final int currentPage;
15 final PageController pageController;
16
17 @override
18 // ignore: library_private_types_in_public_api
19 _PageNavigatorState createState() => _PageNavigatorState();
20}
21
22class _PageNavigatorState extends State<PageNavigator> {
23 late PageController _pageController;
24 late int _currentPage;
25 late int _totalPages;
26
27 @override
28 void initState() {
29 super.initState();
30 _currentPage = widget.currentPage;
31 _totalPages = widget.tottalPages;
32 _pageController = widget.pageController;
33 _pageController.addListener(() {
34 setState(() {
35 _currentPage = _pageController.page?.round() ?? 0;
36 });
37 });
38 }
39
41 if (_currentPage > 0) {
42 _pageController.previousPage(
43 duration: Duration(milliseconds: 300),
44 curve: Curves.ease,
45 );
46 }
47 }
48
50 if (_currentPage < _totalPages - 1) {
51 _pageController.nextPage(
52 duration: Duration(milliseconds: 300),
53 curve: Curves.ease,
54 );
55 }
56 }
57
58 @override
59 void dispose() {
60 _pageController.dispose();
61 super.dispose();
62 }
63
64 @override
65 Widget build(BuildContext context) {
66 return Padding(
67 padding: EdgeInsets.symmetric(horizontal: 25.sp),
68 child: Row(
69 children: [
70 Expanded(
71 child: ElevatedButton(
72 onPressed: _currentPage > 0 ? _goToPreviousPage : null,
73 style: ElevatedButton.styleFrom(
74 padding: EdgeInsets.symmetric(vertical: 12.sp),
75 shape: RoundedRectangleBorder(
76 borderRadius: BorderRadius.circular(80.0),
77 ),
78 ),
79 child: Row(
80 mainAxisAlignment: MainAxisAlignment.center,
81 children: [
82 Icon(HugeIcons.strokeRoundedArrowLeft02),
83 SizedBox(width: 8.sp),
84 Text('Previous'),
85 ],
86 ),
87 ),
88 ),
89 SizedBox(width: 16),
90 Expanded(
91 child: ElevatedButton(
92 onPressed: _currentPage < _totalPages - 1
94 : () {
95 Navigator.of(context).pop(); // Pops the current screen
96 },
97 style: ElevatedButton.styleFrom(
98 padding: EdgeInsets.symmetric(vertical: 12.sp),
99 shape: RoundedRectangleBorder(
100 borderRadius: BorderRadius.circular(80.0),
101 ),
102 ),
103 child: Row(
104 mainAxisAlignment: MainAxisAlignment.center,
105 children: [
106 Text(_currentPage < _totalPages - 1 ? 'Next' : 'Done'),
107 if (_currentPage < _totalPages - 1) ...[
108 SizedBox(width: 8),
109 Icon(HugeIcons.strokeRoundedArrowRight02),
110 ],
111 ],
112 ),
113 ),
114 ),
115 ],
116 ),
117 );
118 }
119}
final PageController pageController
override _PageNavigatorState createState()
const PageNavigator({ super.key, required this.tottalPages, required this.currentPage, required this.pageController, })
override void dispose()
final Widget child
final EdgeInsets padding
override void initState()
class EnergyScreen extends StatefulWidget _pageController
override Widget build(BuildContext context)
late int _currentPage
void _goToPreviousPage()
late int _totalPages
void _goToNextPage()