-
Notifications
You must be signed in to change notification settings - Fork 64
/
27. flutter_animated_bottomsheet.dart
79 lines (73 loc) · 2.67 KB
/
27. flutter_animated_bottomsheet.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
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 {
bool _isExpanded = false;
bool get isExpanded => _isExpanded;
void toggleExpansion() {
_isExpanded = !_isExpanded;
notifyListeners();
}
}
class FlutterAnimatedBottomSheet extends StatelessWidget {
const FlutterAnimatedBottomSheet({super.key});
@override
Widget build(BuildContext context) {
myBottomSheet() {
return showModalBottomSheet(
isScrollControlled: true,
isDismissible: true,
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),
context: context,
builder: (context) {
BottomSheetNotifier bottomSheetNotifier({required bool renderUI}) =>
Provider.of<BottomSheetNotifier>(context, listen: renderUI);
bool isExpanded = bottomSheetNotifier(renderUI: true).isExpanded;
return AnimatedContainer(
color: bgColorFaint,
height: isExpanded ? 700 : 300,
width: 500,
duration: const Duration(seconds: 1),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
GestureDetector(
onTap: () {
bottomSheetNotifier(renderUI: false).toggleExpansion();
},
child: CircleAvatar(
backgroundColor: bgColor,
child: Icon(
bottomSheetNotifier(renderUI: true).isExpanded
? Icons.arrow_downward
: Icons.arrow_upward,
color: Colors.white),
),
),
const SizedBox(height: 20),
Text("Some content here", style: boldText()),
Text("Some more additional content here",
style: regulerText),
],
)));
});
}
return Scaffold(
backgroundColor: bgColor,
appBar: AppBar(
backgroundColor: bgColorFaint,
title: Text("Flutter Expandable Sheet 🔥", style: boldText())),
body: Center(
child: ElevatedButton(
child: Text("Show sheet", style: regulerText),
onPressed: () {
myBottomSheet();
},
),
),
);
}
}