circular_modal.dart
3.44 KB
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
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
class AvatarBottomSheet extends StatelessWidget {
final Widget child;
final Animation<double> animation;
const AvatarBottomSheet(
{Key? key, required this.child, required this.animation})
: super(key: key);
@override
Widget build(BuildContext context) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 12),
SafeArea(
bottom: false,
child: AnimatedBuilder(
animation: animation,
builder: (context, child) => Transform.translate(
offset: Offset(0, (1 - animation.value) * 100),
child: Opacity(
child: child, opacity: max(0, animation.value * 2 - 1))),
child: Row(
children: <Widget>[
SizedBox(width: 20),
CircleAvatar(
child: Text(
'JB',
style: TextStyle(color: Colors.black),
),
radius: 32,
backgroundColor: Colors.blueAccent,
),
],
),
),
),
SizedBox(height: 12),
Flexible(
flex: 1,
fit: FlexFit.loose,
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15), topRight: Radius.circular(15)),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).scaffoldBackgroundColor,
boxShadow: [
BoxShadow(
blurRadius: 10,
color: Colors.black12,
spreadRadius: 5,
),
],
),
width: double.infinity,
child: MediaQuery.removePadding(
context: context, removeTop: true, child: child),
),
),
),
],
),
);
}
}
Future<T?> showAvatarModalBottomSheet<T>({
required BuildContext context,
required WidgetBuilder builder,
Color? backgroundColor,
double? elevation,
ShapeBorder? shape,
Clip? clipBehavior,
Color barrierColor = Colors.black87,
bool bounce = true,
bool expand = false,
AnimationController? secondAnimation,
bool useRootNavigator = false,
bool isDismissible = true,
bool enableDrag = true,
Duration? duration,
}) async {
assert(debugCheckHasMediaQuery(context));
assert(debugCheckHasMaterialLocalizations(context));
final result = await Navigator.of(context, rootNavigator: useRootNavigator)
.push(ModalBottomSheetRoute<T>(
builder: builder,
containerBuilder: (_, animation, child) => AvatarBottomSheet(
child: child,
animation: animation,
),
bounce: bounce,
secondAnimationController: secondAnimation,
expanded: expand,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
isDismissible: isDismissible,
modalBarrierColor: barrierColor,
enableDrag: enableDrag,
duration: duration,
));
return result;
}