-
Notifications
You must be signed in to change notification settings - Fork 64
/
35.flutter_custom_tab.dart
118 lines (106 loc) · 3.58 KB
/
35.flutter_custom_tab.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import 'package:flutter/material.dart';
import 'package:ig_posts/season_2/63.transperant_design_pattern.dart';
import 'package:ig_posts/utils/colors.dart';
import 'package:provider/provider.dart';
class TabNavigatorNotifier extends ChangeNotifier {
int selectedIndex = 0;
void setTabIndex({required int newIndex}) {
selectedIndex = newIndex;
notifyListeners();
}
}
class FlutterTabNavigataorView extends StatefulWidget {
const FlutterTabNavigataorView({super.key});
@override
State<FlutterTabNavigataorView> createState() =>
_FlutterTabNavigataorViewState();
}
class _FlutterTabNavigataorViewState extends State<FlutterTabNavigataorView> {
TabNavigatorNotifier tabNavigatorNotifier({required bool renderUI}) =>
Provider.of<TabNavigatorNotifier>(context, listen: renderUI);
PageController pageController = PageController();
@override
Widget build(BuildContext context) {
showTabHolder() {
miniTab(
{required int index,
required IconData iconData,
required String title}) {
bool isSelectedIndex =
tabNavigatorNotifier(renderUI: true).selectedIndex == index;
return GestureDetector(
onTap: () {
pageController.jumpToPage(index);
tabNavigatorNotifier(renderUI: false).setTabIndex(newIndex: index);
},
child: Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(iconData, color: KConstantColors.whiteColor),
SizedBox(height: 10),
if (isSelectedIndex)
Container(
width: 20,
height: 2,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: KConstantColors.purpleColor),
)
],
),
),
),
);
}
return Row(
children: [
miniTab(index: 0, iconData: Icons.home, title: "Home"),
SizedBox(width: 10),
miniTab(index: 1, iconData: Icons.wifi, title: "Wifi"),
SizedBox(width: 10),
miniTab(index: 2, iconData: Icons.label, title: "Tag"),
],
);
}
showPageContent() {
_pageContent({required String title, required String data}) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: KConstantTextstyles.bold(fontSize: 42)),
Text(data, style: KConstantTextstyles.light(fontSize: 12)),
],
);
}
return SizedBox(
height: 400,
width: 500,
child: PageView(
controller: pageController,
children: [
_pageContent(title: "Home", data: "Some data reguarding home view"),
_pageContent(title: "Wifi", data: "Some data reguarding wifi view"),
_pageContent(title: "Tag", data: "Some data reguarding tag view")
],
),
);
}
return Scaffold(
backgroundColor: KConstantColors.bgColor,
appBar: CustomAppBar(title: "Custom Tab Navigator"),
body: Column(
children: [
SizedBox(height: 50),
showTabHolder(),
SizedBox(height: 5),
showPageContent()
],
),
);
}
}