2020-09-01 21:36:58 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2021-02-09 15:12:13 +01:00
|
|
|
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
|
2020-09-01 21:36:58 +02:00
|
|
|
|
2021-02-09 15:12:13 +01:00
|
|
|
/// Should be spawned with a [showBottomModal], not routed to.
|
2020-09-01 21:36:58 +02:00
|
|
|
class BottomModal extends StatelessWidget {
|
2021-04-09 00:11:44 +02:00
|
|
|
final String? title;
|
2021-02-09 15:12:13 +01:00
|
|
|
final EdgeInsets padding;
|
|
|
|
final Widget child;
|
2020-09-01 21:36:58 +02:00
|
|
|
|
2021-02-09 15:12:13 +01:00
|
|
|
const BottomModal({
|
|
|
|
this.title,
|
|
|
|
this.padding = EdgeInsets.zero,
|
2021-04-09 00:11:44 +02:00
|
|
|
required this.child,
|
|
|
|
});
|
2020-09-01 21:36:58 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-16 23:22:04 +02:00
|
|
|
final theme = Theme.of(context);
|
2020-09-01 21:36:58 +02:00
|
|
|
|
2020-09-02 16:54:29 +02:00
|
|
|
return SafeArea(
|
|
|
|
child: Padding(
|
2021-01-03 18:03:59 +01:00
|
|
|
padding: const EdgeInsets.all(8),
|
2021-02-09 15:12:13 +01:00
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
2021-02-24 20:52:18 +01:00
|
|
|
color: Colors.grey.withOpacity(0.3),
|
2021-02-09 15:12:13 +01:00
|
|
|
),
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
child: Material(
|
|
|
|
clipBehavior: Clip.antiAlias,
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
if (title != null) ...[
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 70),
|
|
|
|
child: Text(
|
2021-04-09 00:11:44 +02:00
|
|
|
title!,
|
2021-02-09 15:12:13 +01:00
|
|
|
style: theme.textTheme.subtitle2,
|
|
|
|
textAlign: TextAlign.left,
|
|
|
|
),
|
2020-09-05 23:48:30 +02:00
|
|
|
),
|
2021-02-09 15:12:13 +01:00
|
|
|
const Divider(
|
|
|
|
indent: 20,
|
|
|
|
endIndent: 20,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
Padding(
|
|
|
|
padding: padding,
|
|
|
|
child: child,
|
2020-09-02 16:54:29 +02:00
|
|
|
),
|
2020-09-05 23:48:30 +02:00
|
|
|
],
|
2021-02-09 15:12:13 +01:00
|
|
|
),
|
2020-09-05 23:48:30 +02:00
|
|
|
),
|
2020-09-02 16:54:29 +02:00
|
|
|
),
|
2020-09-01 21:36:58 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-02-09 15:12:13 +01:00
|
|
|
|
|
|
|
/// Helper function for showing a [BottomModal]
|
2021-04-09 00:11:44 +02:00
|
|
|
Future<T?> showBottomModal<T>({
|
|
|
|
required BuildContext context,
|
|
|
|
required WidgetBuilder builder,
|
|
|
|
String? title,
|
2021-02-09 15:12:13 +01:00
|
|
|
EdgeInsets padding = EdgeInsets.zero,
|
|
|
|
}) =>
|
|
|
|
showCustomModalBottomSheet<T>(
|
|
|
|
context: context,
|
|
|
|
animationCurve: Curves.easeInOutCubic,
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
builder: builder,
|
|
|
|
containerWidget: (context, animation, child) => BottomModal(
|
|
|
|
title: title,
|
|
|
|
padding: padding,
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
);
|