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

155 lines
3.4 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({
Key key,
2020-11-30 12:03:55 +02:00
@required VoidCallback onPressed,
2021-02-15 20:58:29 +02:00
String title,
Widget child,
}) {
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({
Key key,
@required VoidCallback onPressed,
@required String title,
}) =>
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
);
2020-12-03 18:52:53 +02:00
static iconText({
Key key,
@required VoidCallback onPressed,
@required String title,
@required Icon icon,
}) =>
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({
Key key,
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);
final VoidCallback onPressed;
final String title;
2021-02-15 20:58:29 +02:00
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({
Key key,
this.onPressed,
this.title,
}) : super(key: key);
final VoidCallback onPressed;
final String title;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onPressed,
child: Container(
height: 48,
width: double.infinity,
alignment: Alignment.center,
padding: EdgeInsets.all(12),
child: Text(
title,
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 {
const _IconTextButton({Key key, this.onPressed, this.title, this.icon})
: super(key: key);
final VoidCallback onPressed;
final String title;
final Icon icon;
@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,
)
],
),
),
),
);
}
}