mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
85 lines
2.4 KiB
Dart
85 lines
2.4 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:toolbox/core/persistant_store.dart';
|
|
import 'package:toolbox/view/widget/card_dialog.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
import 'package:toolbox/core/extension/stringx.dart';
|
|
|
|
void unawaited(Future<void> future) {}
|
|
|
|
bool isDarkMode(BuildContext context) =>
|
|
Theme.of(context).brightness == Brightness.dark;
|
|
|
|
void showSnackBar(BuildContext context, Widget child) =>
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: child));
|
|
|
|
void showSnackBarWithAction(BuildContext context, String content, String action,
|
|
GestureTapCallback onTap) {
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
content: Text(content),
|
|
action: SnackBarAction(
|
|
label: action,
|
|
onPressed: onTap,
|
|
),
|
|
));
|
|
}
|
|
|
|
Future<bool> openUrl(String url) async {
|
|
final uri = url.uri;
|
|
if (!await canLaunchUrl(uri)) {
|
|
return false;
|
|
}
|
|
final ok = await launchUrl(uri);
|
|
if (ok == true) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
Future<T?>? showRoundDialog<T>(
|
|
BuildContext context, String title, Widget child, List<Widget> actions,
|
|
{EdgeInsets? padding, bool barrierDismiss = true}) {
|
|
return showDialog<T>(
|
|
context: context,
|
|
barrierDismissible: barrierDismiss,
|
|
builder: (ctx) {
|
|
return CardDialog(
|
|
title: Text(title),
|
|
content: child,
|
|
actions: actions,
|
|
padding: padding,
|
|
);
|
|
});
|
|
}
|
|
|
|
Widget buildSwitch(BuildContext context, StoreProperty<bool> prop,
|
|
{Function(bool)? func}) {
|
|
return ValueListenableBuilder(
|
|
valueListenable: prop.listenable(),
|
|
builder: (context, bool value, widget) {
|
|
return Switch(
|
|
value: value,
|
|
onChanged: (value) {
|
|
if (func != null) func(value);
|
|
prop.put(value);
|
|
});
|
|
},
|
|
);
|
|
}
|
|
|
|
void setTransparentNavigationBar(BuildContext context) {
|
|
if (Platform.isAndroid) {
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
|
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
|
statusBarColor: Colors.transparent,
|
|
systemNavigationBarColor: Colors.transparent,
|
|
systemNavigationBarContrastEnforced: true,
|
|
systemNavigationBarIconBrightness:
|
|
isDarkMode(context) ? Brightness.light : Brightness.dark,
|
|
));
|
|
}
|
|
}
|