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

85 lines
2.4 KiB
Dart
Raw Permalink 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,
});
@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(
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(
title!,
2021-02-09 15:12:13 +01:00
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,
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,
),
);