lemmur-app-android/lib/widgets/bottom_modal.dart

87 lines
2.5 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2021-02-09 15:12:13 +01:00
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
2021-02-09 15:12:13 +01:00
/// Should be spawned with a [showBottomModal], not routed to.
class BottomModal extends StatelessWidget {
final String title;
2021-02-09 15:12:13 +01:00
final EdgeInsets padding;
final Widget child;
2021-02-09 15:12:13 +01:00
const BottomModal({
this.title,
this.padding = EdgeInsets.zero,
@required this.child,
}) : assert(padding != null),
assert(child != null);
@override
Widget build(BuildContext context) {
2020-09-16 23:22:04 +02:00
final theme = Theme.of(context);
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(
color: Colors.grey.withOpacity(0.5),
width: 0.2,
),
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(
title,
style: theme.textTheme.subtitle2,
textAlign: TextAlign.left,
),
),
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
),
],
2021-02-09 15:12:13 +01:00
),
),
2020-09-02 16:54:29 +02:00
),
),
),
);
}
}
2021-02-09 15:12:13 +01:00
/// Helper function for showing a [BottomModal]
Future<T> showBottomModal<T>({
@required BuildContext context,
@required WidgetBuilder builder,
String title,
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,
),
);