mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 07:44:26 +01:00
opt.
This commit is contained in:
11
lib/core/extension/context/common.dart
Normal file
11
lib/core/extension/context/common.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
extension ContextX on BuildContext {
|
||||
void pop<T extends Object?>([T? result]) {
|
||||
Navigator.of(this).pop<T>(result);
|
||||
}
|
||||
|
||||
bool get canPop => Navigator.of(this).canPop();
|
||||
|
||||
bool get isDark => Theme.of(this).brightness == Brightness.dark;
|
||||
}
|
||||
@@ -1,55 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:toolbox/view/widget/rebuild.dart';
|
||||
import 'package:toolbox/core/extension/context/common.dart';
|
||||
|
||||
import '../../data/model/server/snippet.dart';
|
||||
import '../../data/provider/snippet.dart';
|
||||
import '../../data/res/ui.dart';
|
||||
import '../../locator.dart';
|
||||
import '../../view/widget/input_field.dart';
|
||||
import '../../view/widget/picker.dart';
|
||||
import '../route.dart';
|
||||
|
||||
extension ContextX on BuildContext {
|
||||
void pop<T extends Object?>([T? result]) {
|
||||
Navigator.of(this).pop<T>(result);
|
||||
}
|
||||
|
||||
bool get canPop => Navigator.of(this).canPop();
|
||||
|
||||
bool get isDark => Theme.of(this).brightness == Brightness.dark;
|
||||
}
|
||||
|
||||
extension SnackBarX on BuildContext {
|
||||
void showSnackBar(String text) =>
|
||||
ScaffoldMessenger.of(this).showSnackBar(SnackBar(
|
||||
content: Text(text),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
));
|
||||
|
||||
void showSnackBarWithAction(
|
||||
String content,
|
||||
String action,
|
||||
GestureTapCallback onTap,
|
||||
) {
|
||||
ScaffoldMessenger.of(this).showSnackBar(SnackBar(
|
||||
content: Text(content),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
action: SnackBarAction(
|
||||
label: action,
|
||||
onPressed: onTap,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
void showRestartSnackbar({String? btn, String? msg}) {
|
||||
showSnackBarWithAction(
|
||||
msg ?? 'Need restart to take effect',
|
||||
btn ?? 'Restart',
|
||||
() => RebuildWidget.restartApp(this),
|
||||
);
|
||||
}
|
||||
}
|
||||
import '../../../data/model/server/snippet.dart';
|
||||
import '../../../data/provider/snippet.dart';
|
||||
import '../../../data/res/ui.dart';
|
||||
import '../../../locator.dart';
|
||||
import '../../../view/widget/input_field.dart';
|
||||
import '../../../view/widget/picker.dart';
|
||||
import '../../route.dart';
|
||||
|
||||
extension DialogX on BuildContext {
|
||||
Future<T?> showRoundDialog<T>({
|
||||
@@ -74,7 +33,7 @@ extension DialogX on BuildContext {
|
||||
|
||||
void showLoadingDialog({bool barrierDismiss = false}) {
|
||||
showRoundDialog(
|
||||
child: centerSizedLoading,
|
||||
child: UIs.centerSizedLoading,
|
||||
barrierDismiss: barrierDismiss,
|
||||
);
|
||||
}
|
||||
33
lib/core/extension/context/snackbar.dart
Normal file
33
lib/core/extension/context/snackbar.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/view/widget/rebuild.dart';
|
||||
|
||||
extension SnackBarX on BuildContext {
|
||||
void showSnackBar(String text) =>
|
||||
ScaffoldMessenger.of(this).showSnackBar(SnackBar(
|
||||
content: Text(text),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
));
|
||||
|
||||
void showSnackBarWithAction(
|
||||
String content,
|
||||
String action,
|
||||
GestureTapCallback onTap,
|
||||
) {
|
||||
ScaffoldMessenger.of(this).showSnackBar(SnackBar(
|
||||
content: Text(content),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
action: SnackBarAction(
|
||||
label: action,
|
||||
onPressed: onTap,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
void showRestartSnackbar({String? btn, String? msg}) {
|
||||
showSnackBarWithAction(
|
||||
msg ?? 'Need restart to take effect',
|
||||
btn ?? 'Restart',
|
||||
() => RebuildWidget.restartApp(this),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import 'dart:async';
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:toolbox/core/extension/context.dart';
|
||||
import 'package:toolbox/core/extension/context/dialog.dart';
|
||||
import 'package:toolbox/core/extension/stringx.dart';
|
||||
import 'package:toolbox/core/extension/uint8list.dart';
|
||||
|
||||
@@ -70,7 +70,7 @@ extension SSHClientX on SSHClient {
|
||||
if (isRequestingPwd) return;
|
||||
isRequestingPwd = true;
|
||||
if (data.contains('[sudo] password for ')) {
|
||||
final user = pwdRequestWithUserReg.firstMatch(data)?.group(1);
|
||||
final user = Miscs.pwdRequestWithUserReg.firstMatch(data)?.group(1);
|
||||
if (context == null) return;
|
||||
final pwd = await context.showPwdDialog(user);
|
||||
if (pwd == null || pwd.isEmpty) {
|
||||
|
||||
Reference in New Issue
Block a user