mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-06-07 14:12:41 -04:00
more refactor
This commit is contained in:
parent
ba4ef05a28
commit
b83aa3a64b
39 changed files with 722 additions and 514 deletions
|
@ -5,6 +5,7 @@ import 'package:flutter_spinkit/flutter_spinkit.dart';
|
|||
import 'package:flutter_translate/flutter_translate.dart';
|
||||
import 'package:motion_toast/motion_toast.dart';
|
||||
import 'package:quickalert/quickalert.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../theme/theme.dart';
|
||||
|
||||
|
@ -41,6 +42,24 @@ Widget waitingPage(BuildContext context) => ColoredBox(
|
|||
color: Theme.of(context).scaffoldBackgroundColor,
|
||||
child: Center(child: buildProgressIndicator(context)));
|
||||
|
||||
Widget errorPage(BuildContext context, Object err, StackTrace? st) =>
|
||||
ColoredBox(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
child: Center(child: Text(err.toString())));
|
||||
|
||||
Widget asyncValueBuilder<T>(
|
||||
AsyncValue<T> av, Widget Function(BuildContext, T) builder) =>
|
||||
av.when(
|
||||
loading: () => const Builder(builder: waitingPage),
|
||||
error: (e, st) =>
|
||||
Builder(builder: (context) => errorPage(context, e, st)),
|
||||
data: (d) => Builder(builder: (context) => builder(context, d)));
|
||||
|
||||
extension AsyncValueBuilderExt<T> on AsyncValue<T> {
|
||||
Widget builder(Widget Function(BuildContext, T) builder) =>
|
||||
asyncValueBuilder<T>(this, builder);
|
||||
}
|
||||
|
||||
Future<void> showErrorModal(
|
||||
BuildContext context, String title, String text) async {
|
||||
await QuickAlert.show(
|
||||
|
@ -135,3 +154,7 @@ Future<T?> showStyledDialog<T>(
|
|||
borderRadius: BorderRadius.circular(12))),
|
||||
child: child.paddingAll(0)))));
|
||||
}
|
||||
|
||||
bool get isPlatformDark =>
|
||||
WidgetsBinding.instance.platformDispatcher.platformBrightness ==
|
||||
Brightness.dark;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue