-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
47 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,6 @@ | |
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
// @author TechAurelian <[email protected]> (https://techaurelian.com) | ||
|
||
// cSpell:ignore endregion | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
@@ -17,8 +14,6 @@ class Counter { | |
/// Creates a counter of the specified [type]. | ||
Counter(this.type); | ||
|
||
//#region Counter value | ||
|
||
/// The counter value. | ||
int _value = 0; | ||
|
||
|
@@ -46,12 +41,8 @@ class Counter { | |
_setValue(0); | ||
} | ||
|
||
//#endregion | ||
|
||
//#region Persistent storage | ||
|
||
/// Returns the persistent storage key for each counter type. | ||
static String _counterKey(CounterType type) => '${describeEnum(type)}_counter'; | ||
static String _counterKey(CounterType type) => '${type.name}_counter'; | ||
|
||
/// Saves the counter value to persistent storage. | ||
Future<void> _saveValue() async { | ||
|
@@ -64,10 +55,6 @@ class Counter { | |
_value = preferences.getInt(_counterKey(type)) ?? 0; | ||
} | ||
|
||
//#endregion | ||
|
||
//#region Counter type, color, name | ||
|
||
/// The counter type. | ||
final CounterType type; | ||
|
||
|
@@ -82,8 +69,8 @@ class Counter { | |
|
||
/// Returns the name of the specified counter type (e.g. "Black Counter"). | ||
static String nameOf(CounterType type) { | ||
final String name = describeEnum(type); | ||
return '${name.substring(0, 1).toUpperCase()}${name.substring(1).toLowerCase()} Counter'; | ||
final String name = type.name; | ||
return '${name[0].toUpperCase()}${name.substring(1).toLowerCase()} Counter'; | ||
} | ||
|
||
/// A map with the corresponding [Color] value for each counter type. | ||
|
@@ -100,8 +87,6 @@ class Counter { | |
CounterType.orange: Colors.orange, | ||
CounterType.grey: Colors.grey, | ||
}; | ||
|
||
//#endregion | ||
} | ||
|
||
/// Provides a map of counters for each counter type, and keeps a reference to the current counter. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
// @author TechAurelian <[email protected]> (https://techaurelian.com) | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
|
@@ -16,44 +17,27 @@ String toDecimalString(BuildContext context, int number) { | |
/// | ||
/// Shows an error [SnackBar] if there is no support for launching the URL. | ||
Future<void> launchUrlExternal(BuildContext context, String url) async { | ||
if (!await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication)) { | ||
showSnackBar(context, 'Failed to open $url'); | ||
try { | ||
await launchUrl(Uri.parse(url), mode: LaunchMode.externalApplication); | ||
} on PlatformException catch (e) { | ||
if (!context.mounted) return; | ||
showSnackBar(context, 'Failed to open $url: ${e.message}'); | ||
} | ||
} | ||
|
||
/// Shows a [SnackBar] with the specified [text] at the bottom of the specified scaffold. | ||
void showSnackBar(BuildContext context, String text) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar( | ||
content: Text(text), | ||
), | ||
); | ||
ScaffoldMessenger.of(context) | ||
..removeCurrentSnackBar() | ||
..showSnackBar(SnackBar(content: Text(text))); | ||
} | ||
|
||
/// Utility Color extension methods. | ||
extension ColorX on Color { | ||
/// Returns the contrast color for this color. | ||
Color contrastOf() => | ||
ThemeData.estimateBrightnessForColor(this) == Brightness.light ? Colors.black : Colors.white; | ||
|
||
/// Creates a material color from any ARGB color value. | ||
MaterialColor createMaterialColor() { | ||
List<double> strengths = <double>[.05]; | ||
Map<int, Color> swatch = <int, Color>{}; | ||
final int r = red, g = green, b = blue; | ||
|
||
for (int i = 1; i < 10; i++) { | ||
strengths.add(0.1 * i); | ||
} | ||
for (var strength in strengths) { | ||
final double ds = 0.5 - strength; | ||
swatch[(strength * 1000).round()] = Color.fromRGBO( | ||
r + ((ds < 0 ? r : (255 - r)) * ds).round(), | ||
g + ((ds < 0 ? g : (255 - g)) * ds).round(), | ||
b + ((ds < 0 ? b : (255 - b)) * ds).round(), | ||
1, | ||
); | ||
} | ||
return MaterialColor(value, swatch); | ||
Color contrastOf() { | ||
return ThemeData.estimateBrightnessForColor(this) == Brightness.light | ||
? Colors.black | ||
: Colors.white; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters