-
Notifications
You must be signed in to change notification settings - Fork 64
/
17.flutter_bottom_sheet.dart
138 lines (130 loc) · 4.65 KB
/
17.flutter_bottom_sheet.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import 'package:flutter/material.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 BottomSheetNotifier extends ChangeNotifier {
List<String> tags = [
"Lion",
"Tiger",
"Elephant",
"Cheetah",
"Fish",
"Dolphin",
"Rabbit",
"Dog",
"Swan",
"Cat",
"Donkey",
"Frog"
];
List<String> queriedData = [];
addToList({required String kValue}) {
if (queriedData.contains(kValue)) {
queriedData.remove(kValue);
notifyListeners();
} else {
queriedData.add(kValue);
notifyListeners();
}
}
}
class FlutterBottomSheetView extends StatelessWidget {
const FlutterBottomSheetView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
BottomSheetNotifier bottomSheetNotifier({required bool renderUI}) =>
Provider.of<BottomSheetNotifier>(context, listen: renderUI);
List<String> data = bottomSheetNotifier(renderUI: true).queriedData;
_showTags() {
return GridView.builder(
shrinkWrap: true,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
childAspectRatio: 2, crossAxisCount: 4),
itemCount: bottomSheetNotifier(renderUI: false).tags.length,
itemBuilder: (BuildContext context, int index) {
BottomSheetNotifier bottomSheetNotifier({required bool renderUI}) =>
Provider.of<BottomSheetNotifier>(context, listen: renderUI);
return ActionChip(
backgroundColor: bottomSheetNotifier(renderUI: true)
.queriedData
.contains(
bottomSheetNotifier(renderUI: false).tags[index])
? Colors.blue
: bgColor,
label: Text(bottomSheetNotifier(renderUI: false).tags[index],
style: regulerText),
onPressed: () {
bottomSheetNotifier(renderUI: false).addToList(
kValue: bottomSheetNotifier(renderUI: false).tags[index]);
});
},
);
}
_showBottomSheet() {
return showModalBottomSheet(
isScrollControlled: true,
backgroundColor: bgColorFaint,
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(25.0)),
context: context,
builder: (context) {
return SizedBox(
height: 800,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Select tags", style: boldText(fSize: 50)),
Text("You can select more than 5 tags for the app",
style: regulerText),
const SizedBox(height: 50),
_showTags(),
const SizedBox(height: 10),
ActionChip(
backgroundColor: Colors.blue,
onPressed: () {
Navigator.pop(context);
},
label: Text("Dismiss", style: regulerText)),
const SizedBox(height: 80),
Text("Follow @abhishvek for more! 🚀",
style: boldText(fSize: 16)),
],
),
);
});
}
return Scaffold(
appBar: AppBar(
backgroundColor: bgColorFaint,
title: Text("Flutter bottom sheet 🔥", style: boldText(fSize: 20))),
backgroundColor: bgColor,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (bottomSheetNotifier(renderUI: true).queriedData.isNotEmpty)
Text("Selected Tags", style: boldText(fSize: 30)),
const SizedBox(height: 10),
if (bottomSheetNotifier(renderUI: true).queriedData.isNotEmpty)
GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
childAspectRatio: 2, crossAxisCount: 4),
shrinkWrap: true,
itemCount: data.length,
itemBuilder: (BuildContext context, int index) {
return Chip(
backgroundColor: bgColorFaint, label: Text(data[index]));
},
),
ActionChip(
backgroundColor: Colors.blue,
onPressed: () {
_showBottomSheet();
},
label: Text("Select tags", style: regulerText)),
],
),
),
);
}
}