-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy path22. custom_tabbar.dart
83 lines (74 loc) · 2.55 KB
/
22. custom_tabbar.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
import 'package:flutter/material.dart';
import 'package:ig_posts/features/0.abhishvek_header.dart';
import 'package:ig_posts/features/1.flutter_frost_glass.view.dart';
import 'package:ig_posts/features/5.flutter_swiggy_button.dart';
import 'package:provider/provider.dart';
class TabNotifier extends ChangeNotifier {
int tabIndex = 0;
void setTabIndex({required int kValue}) {
tabIndex = kValue;
notifyListeners();
}
}
class CustomTabBarWidget extends StatelessWidget {
const CustomTabBarWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
TabNotifier tabNotifier({required bool renderUI}) =>
Provider.of<TabNotifier>(context, listen: renderUI);
Widget tabHolder({required int index, required String title}) {
return ActionChip(
backgroundColor: tabNotifier(renderUI: true).tabIndex == index
? Colors.blue
: bgColorFaint,
onPressed: () {
tabNotifier(renderUI: false).setTabIndex(kValue: index);
},
label: Text(title, style: boldText()),
);
}
int kIndex = tabNotifier(renderUI: true).tabIndex;
Widget mainWidget() {
subWidget({required String title}) {
return Container(
height: 650,
width: 400,
decoration: BoxDecoration(
border: Border.all(width: 0.2, color: Colors.white),
borderRadius: BorderRadius.circular(25)),
child: Center(child: Text(title, style: boldText(fSize: 26))),
);
}
if (kIndex == 0) {
return subWidget(title: "Content for home");
}
if (kIndex == 1) {
return subWidget(title: "Content for profile");
}
return subWidget(title: "Content for settings");
}
return Scaffold(
appBar: AppBar(
backgroundColor: bgColorFaint,
title: Text("Flutter Custom TabBar", style: boldText(fSize: 16))),
backgroundColor: bgColor,
body: Column(
children: [
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
tabHolder(index: 0, title: "Home"),
tabHolder(index: 1, title: "Profile"),
tabHolder(index: 2, title: "Settings"),
],
),
const Divider(color: Colors.white, thickness: 0.1),
const SizedBox(height: 10),
mainWidget(),
const SizedBox(height: 20),
const AbhishvekHeaderWidget(),
],
));
}
}