Add base skeleton
This commit is contained in:
38
moneymgr_mobile/lib/utils/extensions.dart
Normal file
38
moneymgr_mobile/lib/utils/extensions.dart
Normal file
@ -0,0 +1,38 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
extension BuildContextX on BuildContext {
|
||||
/// A convenient way to access [ThemeData.colorScheme] of the current context.
|
||||
///
|
||||
/// This also prevents confusion with a bunch of other properties of [ThemeData]
|
||||
/// that are less commonly used.
|
||||
ColorScheme get colorScheme => Theme.of(this).colorScheme;
|
||||
|
||||
/// A convenient way to access [ThemeData.textTheme] of the current context.
|
||||
///
|
||||
/// This also prevents confusion with a bunch of other properties of [ThemeData]
|
||||
/// that are less commonly used.
|
||||
TextTheme get textTheme => Theme.of(this).textTheme;
|
||||
|
||||
/// Shows a floating snack bar with text as its content.
|
||||
ScaffoldFeatureController<SnackBar, SnackBarClosedReason> showTextSnackBar(
|
||||
String text,
|
||||
) =>
|
||||
ScaffoldMessenger.of(this).showSnackBar(SnackBar(
|
||||
behavior: SnackBarBehavior.floating,
|
||||
content: Text(text),
|
||||
));
|
||||
|
||||
void showAppLicensePage() => showLicensePage(
|
||||
context: this,
|
||||
useRootNavigator: true,
|
||||
applicationName: 'DummyMart',
|
||||
);
|
||||
}
|
||||
|
||||
extension ThemeModeX on ThemeMode {
|
||||
String get label => switch (this) {
|
||||
ThemeMode.system => 'System',
|
||||
ThemeMode.light => 'Light',
|
||||
ThemeMode.dark => 'Dark',
|
||||
};
|
||||
}
|
19
moneymgr_mobile/lib/utils/hooks.dart
Normal file
19
moneymgr_mobile/lib/utils/hooks.dart
Normal file
@ -0,0 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
|
||||
typedef AsyncTask = ({
|
||||
ValueNotifier<Future<void>?> pending,
|
||||
AsyncSnapshot<void> snapshot,
|
||||
bool hasError,
|
||||
});
|
||||
|
||||
/// Creates a hook that provides a [snapshot] of the current asynchronous task passed
|
||||
/// to [pending] and a [hasError] value.
|
||||
AsyncTask useAsyncTask() {
|
||||
final pending = useState<Future<void>?>(null);
|
||||
final snapshot = useFuture(pending.value);
|
||||
final hasError =
|
||||
snapshot.hasError && snapshot.connectionState != ConnectionState.waiting;
|
||||
|
||||
return (pending: pending, snapshot: snapshot, hasError: hasError);
|
||||
}
|
Reference in New Issue
Block a user