selfprivacy.org.app/lib/ui/components/brand_button/brand_button.dart

92 lines
2.3 KiB
Dart
Raw Normal View History

2020-11-29 22:07:46 +02:00
import 'package:flutter/material.dart';
import 'package:selfprivacy/ui/components/brand_button/filled_button.dart';
2020-12-08 21:26:51 +02:00
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
2020-11-29 22:07:46 +02:00
2020-12-03 18:52:53 +02:00
enum BrandButtonTypes { rised, text, iconText }
2020-11-29 22:07:46 +02:00
2021-02-15 20:58:29 +02:00
class BrandButton {
2022-06-05 22:36:32 +03:00
static ConstrainedBox rised({
required final VoidCallback? onPressed,
final Key? key,
final String? text,
final Widget? child,
2021-02-15 20:58:29 +02:00
}) {
2021-05-26 00:53:54 +03:00
assert(text == null || child == null, 'required title or child');
assert(text != null || child != null, 'required title or child');
2022-05-17 01:41:00 +03:00
return ConstrainedBox(
2022-05-24 21:55:39 +03:00
constraints: const BoxConstraints(
2022-05-17 01:41:00 +03:00
minHeight: 48,
minWidth: double.infinity,
),
child: FilledButton(
key: key,
title: text,
onPressed: onPressed,
child: child,
),
2021-02-15 20:58:29 +02:00
);
}
2020-11-29 22:07:46 +02:00
2022-06-05 22:36:32 +03:00
static ConstrainedBox text({
required final VoidCallback onPressed,
required final String title,
final Key? key,
2020-11-30 12:03:55 +02:00
}) =>
2022-05-17 01:41:00 +03:00
ConstrainedBox(
2022-05-24 21:55:39 +03:00
constraints: const BoxConstraints(
minHeight: 40,
2022-05-17 01:41:00 +03:00
minWidth: double.infinity,
),
child: TextButton(onPressed: onPressed, child: Text(title)),
2020-11-30 12:03:55 +02:00
);
static IconTextButton emptyWithIconText({
2022-06-05 22:36:32 +03:00
required final VoidCallback onPressed,
required final String title,
required final Icon icon,
final Key? key,
2020-12-03 18:52:53 +02:00
}) =>
IconTextButton(
2020-12-03 18:52:53 +02:00
key: key,
title: title,
2021-02-15 20:58:29 +02:00
onPressed: onPressed,
2020-12-03 18:52:53 +02:00
icon: icon,
);
2020-11-29 22:07:46 +02:00
}
class IconTextButton extends StatelessWidget {
const IconTextButton({
super.key,
this.onPressed,
this.title,
this.icon,
});
2020-12-03 18:52:53 +02:00
2021-03-15 17:39:44 +02:00
final VoidCallback? onPressed;
final String? title;
final Icon? icon;
2020-12-03 18:52:53 +02:00
@override
2022-06-05 22:36:32 +03:00
Widget build(final BuildContext context) => Material(
color: Colors.transparent,
child: InkWell(
onTap: onPressed,
child: Container(
height: 48,
width: double.infinity,
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
BrandText.body1(title),
Padding(
padding: const EdgeInsets.all(12.0),
child: icon,
)
],
),
2020-12-03 18:52:53 +02:00
),
),
);
2020-12-03 18:52:53 +02:00
}