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

156 lines
3.5 KiB
Dart
Raw Normal View History

2020-11-29 22:07:46 +02:00
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:selfprivacy/config/brand_colors.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 {
2020-11-29 22:07:46 +02:00
static rised({
2021-03-15 17:39:44 +02:00
Key? key,
required VoidCallback? onPressed,
String? title,
Widget? child,
2021-02-15 20:58:29 +02:00
}) {
assert(title == null || child == null, 'required title or child');
assert(title != null || child != null, 'required title or child');
return _RisedButton(
key: key,
title: title,
onPressed: onPressed,
child: child,
);
}
2020-11-29 22:07:46 +02:00
2020-11-30 12:03:55 +02:00
static text({
2021-03-15 17:39:44 +02:00
Key? key,
required VoidCallback onPressed,
required String title,
2020-11-30 12:03:55 +02:00
}) =>
2021-02-15 20:58:29 +02:00
_TextButton(
2020-11-30 12:03:55 +02:00
key: key,
title: title,
2021-02-15 20:58:29 +02:00
onPressed: onPressed,
2020-11-30 12:03:55 +02:00
);
2021-03-26 15:38:39 +02:00
static emptyWithIconText({
2021-03-15 17:39:44 +02:00
Key? key,
required VoidCallback onPressed,
required String title,
required Icon icon,
2020-12-03 18:52:53 +02:00
}) =>
2021-02-15 20:58:29 +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 _RisedButton extends StatelessWidget {
const _RisedButton({
2021-03-15 17:39:44 +02:00
Key? key,
2020-11-29 22:07:46 +02:00
this.onPressed,
this.title,
2021-02-15 20:58:29 +02:00
this.child,
2020-11-29 22:07:46 +02:00
}) : super(key: key);
2021-03-15 17:39:44 +02:00
final VoidCallback? onPressed;
final String? title;
final Widget? child;
2020-11-29 22:07:46 +02:00
@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(24),
child: ColoredBox(
2020-12-06 09:28:31 +02:00
color: onPressed == null
? BrandColors.gray2
: Theme.of(context).primaryColor,
2020-11-29 22:07:46 +02:00
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: onPressed,
child: Container(
height: 48,
width: double.infinity,
alignment: Alignment.center,
padding: EdgeInsets.all(12),
2021-02-15 20:58:29 +02:00
child: child ?? BrandText.buttonTitleText(title),
2020-11-29 22:07:46 +02:00
),
),
),
),
);
}
}
2020-11-30 12:03:55 +02:00
class _TextButton extends StatelessWidget {
const _TextButton({
2021-03-15 17:39:44 +02:00
Key? key,
2020-11-30 12:03:55 +02:00
this.onPressed,
this.title,
}) : super(key: key);
2021-03-15 17:39:44 +02:00
final VoidCallback? onPressed;
final String? title;
2020-11-30 12:03:55 +02:00
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onPressed,
2021-03-25 10:46:07 +02:00
behavior: HitTestBehavior.opaque,
2020-11-30 12:03:55 +02:00
child: Container(
height: 48,
width: double.infinity,
alignment: Alignment.center,
padding: EdgeInsets.all(12),
child: Text(
2021-03-15 17:39:44 +02:00
title!,
2020-11-30 12:03:55 +02:00
style: TextStyle(
color: BrandColors.blue,
fontSize: 16,
fontWeight: FontWeight.bold,
height: 1.5,
),
),
),
);
}
}
2020-12-03 18:52:53 +02:00
class _IconTextButton extends StatelessWidget {
2021-03-15 17:39:44 +02:00
const _IconTextButton({Key? key, this.onPressed, this.title, this.icon})
2020-12-03 18:52:53 +02:00
: super(key: key);
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
Widget build(BuildContext context) {
return Material(
color: Colors.transparent,
child: InkWell(
onTap: onPressed,
child: Container(
height: 48,
width: double.infinity,
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
2020-12-08 21:26:51 +02:00
BrandText.body1(title),
2020-12-03 18:52:53 +02:00
Padding(
padding: const EdgeInsets.all(12.0),
child: icon,
)
],
),
),
),
);
}
}