From 803530e959e25c3605aa9f6a1be76bb7d2c49b27 Mon Sep 17 00:00:00 2001 From: Aliaksei Tratseuski Date: Wed, 31 Jan 2024 07:48:07 +0400 Subject: [PATCH] BrandButton.rised rewrite as SPBrandButton widget --- lib/ui/components/buttons/brand_button.dart | 10 ++++--- lib/ui/components/buttons/buttons.dart | 2 ++ .../components/buttons/sp_brand_button.dart | 28 +++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 lib/ui/components/buttons/buttons.dart create mode 100644 lib/ui/components/buttons/sp_brand_button.dart diff --git a/lib/ui/components/buttons/brand_button.dart b/lib/ui/components/buttons/brand_button.dart index c381af43..bb2e722a 100644 --- a/lib/ui/components/buttons/brand_button.dart +++ b/lib/ui/components/buttons/brand_button.dart @@ -7,8 +7,9 @@ class BrandButton { final String? text, final Widget? child, }) { - assert(text == null || child == null, 'required title or child'); - assert(text != null || child != null, 'required title or child'); + assert((text ?? child) != null, 'either title or child must not be empty'); + assert(text != null || child != null, 'title or child must be provided'); + return ConstrainedBox( constraints: const BoxConstraints( minHeight: 48, @@ -28,8 +29,9 @@ class BrandButton { final String? text, final Widget? child, }) { - assert(text == null || child == null, 'required title or child'); - assert(text != null || child != null, 'required title or child'); + assert((text ?? child) != null, 'either title or child must not be empty'); + assert(text != null || child != null, 'title or child must be provided'); + return ConstrainedBox( constraints: const BoxConstraints( minWidth: double.infinity, diff --git a/lib/ui/components/buttons/buttons.dart b/lib/ui/components/buttons/buttons.dart new file mode 100644 index 00000000..49e0bb07 --- /dev/null +++ b/lib/ui/components/buttons/buttons.dart @@ -0,0 +1,2 @@ +export 'brand_button.dart'; +export 'sp_brand_button.dart'; diff --git a/lib/ui/components/buttons/sp_brand_button.dart b/lib/ui/components/buttons/sp_brand_button.dart new file mode 100644 index 00000000..036b30f2 --- /dev/null +++ b/lib/ui/components/buttons/sp_brand_button.dart @@ -0,0 +1,28 @@ +import 'package:flutter/material.dart'; + +class SPBrandButton extends StatelessWidget { + const SPBrandButton({ + required this.child, + required this.onPressed, + super.key, + }); + + SPBrandButton.text({ + required final String title, + required this.onPressed, + super.key, + }) : child = Text(title); + + final Widget child; + final VoidCallback onPressed; + + @override + Widget build(final BuildContext context) => FilledButton( + // TODO(misterfourtytwo): move button styles to theme configuration + style: const ButtonStyle( + minimumSize: MaterialStatePropertyAll(Size.fromHeight(48)), + ), + onPressed: onPressed, + child: child, + ); +}