From e2595c72111f817fd177771f2a24c02f9823622b Mon Sep 17 00:00:00 2001 From: Zino Hofmann Date: Thu, 20 Aug 2020 14:37:08 +0000 Subject: [PATCH] feat: add more styling support --- CHANGELOG.md | 5 +++++ lib/flavor_config.dart | 1 + lib/src/banner/flavor_banner.dart | 25 +++++++++++++++------ lib/src/config/flavor_config.dart | 19 +++++++++++----- lib/src/dialog/device_info_dialog.dart | 16 +------------ lib/src/dialog/device_info_dialog_tile.dart | 5 ++++- pubspec.yaml | 2 +- 7 files changed, 44 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10ddb30..41cda4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [1.1.0] - 20-08-2020. + +- Added support to define both the `bannerColor` and `textColor`. +- Remove `textDirection` option. + ## [1.0.1] - 20-08-2020. - Added `textDirection` option. diff --git a/lib/flavor_config.dart b/lib/flavor_config.dart index a2ca3fe..8591a02 100644 --- a/lib/flavor_config.dart +++ b/lib/flavor_config.dart @@ -2,4 +2,5 @@ library flavor_config; export 'package:flavor_config/src/config/flavor_config.dart'; export 'package:flavor_config/src/banner/flavor_banner.dart'; +export 'package:flavor_config/src/dialog/device_info_dialog.dart'; export 'package:flavor_config/src/utils/device_utils.dart'; diff --git a/lib/src/banner/flavor_banner.dart b/lib/src/banner/flavor_banner.dart index 4f215c1..9bbe18c 100644 --- a/lib/src/banner/flavor_banner.dart +++ b/lib/src/banner/flavor_banner.dart @@ -4,14 +4,15 @@ import 'package:flavor_config/src/config/flavor_config.dart'; import 'package:flavor_config/src/dialog/device_info_dialog.dart'; class FlavorBanner extends StatelessWidget { - /// The [TextDirection] of the text inside the banner. - final TextDirection textDirection; + /// The [GlobalKey] for when the [FlavorBanner] in not in a context with + /// that includes a [Navigator]. + final GlobalKey navigatorKey; /// The child where the banner should be rendered on top of. final Widget child; FlavorBanner({ - @required this.textDirection, + this.navigatorKey, @required this.child, }); @@ -31,15 +32,25 @@ class FlavorBanner extends StatelessWidget { height: 50, child: CustomPaint( painter: BannerPainter( - message: FlavorConfig.instance.flavorName, - textDirection: textDirection, - layoutDirection: textDirection, + message: FlavorConfig.getFlavorName().toUpperCase(), + textDirection: Directionality.of(context), + layoutDirection: Directionality.of(context), location: BannerLocation.topStart, - color: FlavorConfig.instance.color, + color: FlavorConfig.getBannerColor(), + textStyle: TextStyle( + color: FlavorConfig.getTextColor(), + fontSize: 12.0 * 0.85, + fontWeight: FontWeight.w900, + height: 1.0, + ), ), ), ), onLongPress: () { + if (navigatorKey != null) { + context = navigatorKey.currentState.overlay.context; + } + showDialog( context: context, builder: (BuildContext context) { diff --git a/lib/src/config/flavor_config.dart b/lib/src/config/flavor_config.dart index 7215654..0d55a0f 100644 --- a/lib/src/config/flavor_config.dart +++ b/lib/src/config/flavor_config.dart @@ -8,7 +8,10 @@ class FlavorConfig { final bool bannerEnabled; /// The color of the banner if enabled. - final Color color; + final Color bannerColor; + + /// The color of the text inside the banner if enabled. + final Color textColor; /// The values that belong to the flavor. final Map values; @@ -22,13 +25,15 @@ class FlavorConfig { factory FlavorConfig({ @required String flavorName, bool bannerEnabled = true, - Color color = Colors.pink, + Color bannerColor = Colors.pink, + Color textColor = Colors.white, @required Map values, }) { _instance ??= FlavorConfig._internal( flavorName, bannerEnabled, - color, + bannerColor, + textColor, values, ); @@ -38,7 +43,8 @@ class FlavorConfig { FlavorConfig._internal( this.flavorName, this.bannerEnabled, - this.color, + this.bannerColor, + this.textColor, this.values, ); @@ -49,7 +55,10 @@ class FlavorConfig { static bool isBannerEnabled() => _instance.bannerEnabled; /// Gets the color of the banner if enabled. - static Color getColor() => _instance.color; + static Color getBannerColor() => _instance.bannerColor; + + /// Gets the color of the text inside the banner if enabled. + static Color getTextColor() => _instance.textColor; /// Gets the values that belong to the flavor. static Map getValues() => _instance.values; diff --git a/lib/src/dialog/device_info_dialog.dart b/lib/src/dialog/device_info_dialog.dart index 601a5ed..0513924 100644 --- a/lib/src/dialog/device_info_dialog.dart +++ b/lib/src/dialog/device_info_dialog.dart @@ -2,7 +2,6 @@ import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:flavor_config/src/config/flavor_config.dart'; import 'package:flavor_config/src/dialog/device_info_dialog_android.dart'; import 'package:flavor_config/src/dialog/device_info_dialog_ios.dart'; @@ -14,20 +13,7 @@ class DeviceInfoDialog extends StatelessWidget { @override Widget build(BuildContext context) { return AlertDialog( - contentPadding: EdgeInsets.only( - bottom: 10.0, - ), - title: Container( - padding: EdgeInsets.all(16.0), - color: FlavorConfig.instance.color, - child: Text( - 'Device Info', - style: TextStyle( - color: Colors.white, - ), - ), - ), - titlePadding: EdgeInsets.all(0), + title: Text('Device Info'), content: _getContent(), ); } diff --git a/lib/src/dialog/device_info_dialog_tile.dart b/lib/src/dialog/device_info_dialog_tile.dart index 4817e7a..b4c8720 100644 --- a/lib/src/dialog/device_info_dialog_tile.dart +++ b/lib/src/dialog/device_info_dialog_tile.dart @@ -13,8 +13,11 @@ class DeviceInfoDialogTile extends StatelessWidget { @override Widget build(BuildContext context) { return Padding( - padding: EdgeInsets.all(4.0), + padding: EdgeInsets.symmetric( + vertical: 4.0, + ), child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( name, diff --git a/pubspec.yaml b/pubspec.yaml index 998c361..b47cd5e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flavor_config description: An easy to use package for creating flavors for any environment. -version: 1.0.1 +version: 1.1.0 homepage: https://github.com/zino-hofmann/flavor-config-flutter environment: