Skip to content

Commit

Permalink
feat: add more styling support
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmannZ committed Aug 20, 2020
1 parent af38ad7 commit e2595c7
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 29 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/flavor_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
25 changes: 18 additions & 7 deletions lib/src/banner/flavor_banner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<NavigatorState>] for when the [FlavorBanner] in not in a context with
/// that includes a [Navigator].
final GlobalKey<NavigatorState> navigatorKey;

/// The child where the banner should be rendered on top of.
final Widget child;

FlavorBanner({
@required this.textDirection,
this.navigatorKey,
@required this.child,
});

Expand All @@ -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) {
Expand Down
19 changes: 14 additions & 5 deletions lib/src/config/flavor_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic> values;
Expand All @@ -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<String, dynamic> values,
}) {
_instance ??= FlavorConfig._internal(
flavorName,
bannerEnabled,
color,
bannerColor,
textColor,
values,
);

Expand All @@ -38,7 +43,8 @@ class FlavorConfig {
FlavorConfig._internal(
this.flavorName,
this.bannerEnabled,
this.color,
this.bannerColor,
this.textColor,
this.values,
);

Expand All @@ -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<String, dynamic> getValues() => _instance.values;
Expand Down
16 changes: 1 addition & 15 deletions lib/src/dialog/device_info_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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(),
);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/src/dialog/device_info_dialog_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: <Widget>[
Text(
name,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit e2595c7

Please sign in to comment.