mirror of
https://github.com/StarCitizenToolBox/app.git
synced 2026-02-06 15:10:20 +00:00
feat: Linux Path Basic Support
modified: lib/ui/settings/settings_ui_model.dart
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fluent_ui/fluent_ui.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
@@ -7,105 +8,118 @@ import 'dart:ui' as ui;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:starcitizen_doctor/generated/l10n.dart';
|
||||
|
||||
Future showToast(BuildContext context, String msg, {BoxConstraints? constraints, String? title}) async {
|
||||
return showBaseDialog(context,
|
||||
title: title ?? S.current.app_common_tip,
|
||||
content: Text(msg),
|
||||
actions: [
|
||||
FilledButton(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 2, bottom: 2, left: 8, right: 8),
|
||||
child: Text(S.current.app_common_tip_i_know),
|
||||
),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
],
|
||||
constraints: constraints);
|
||||
/// String extension for cross-platform path compatibility
|
||||
extension PathStringExtension on String {
|
||||
/// Converts path separators to the current platform's format.
|
||||
/// On Windows: / -> \
|
||||
/// On Linux/macOS: \ -> /
|
||||
String get platformPath {
|
||||
if (Platform.isWindows) {
|
||||
return replaceAll('/', '\\');
|
||||
}
|
||||
return replaceAll('\\', '/');
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> showConfirmDialogs(BuildContext context, String title, Widget content,
|
||||
{String confirm = "", String cancel = "", BoxConstraints? constraints}) async {
|
||||
Future showToast(BuildContext context, String msg, {BoxConstraints? constraints, String? title}) async {
|
||||
return showBaseDialog(
|
||||
context,
|
||||
title: title ?? S.current.app_common_tip,
|
||||
content: Text(msg),
|
||||
actions: [
|
||||
FilledButton(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 2, bottom: 2, left: 8, right: 8),
|
||||
child: Text(S.current.app_common_tip_i_know),
|
||||
),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
],
|
||||
constraints: constraints,
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> showConfirmDialogs(
|
||||
BuildContext context,
|
||||
String title,
|
||||
Widget content, {
|
||||
String confirm = "",
|
||||
String cancel = "",
|
||||
BoxConstraints? constraints,
|
||||
}) async {
|
||||
if (confirm.isEmpty) confirm = S.current.app_common_tip_confirm;
|
||||
if (cancel.isEmpty) cancel = S.current.app_common_tip_cancel;
|
||||
|
||||
final r = await showBaseDialog(context,
|
||||
title: title,
|
||||
content: content,
|
||||
actions: [
|
||||
if (confirm.isNotEmpty)
|
||||
FilledButton(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 2, bottom: 2, left: 8, right: 8),
|
||||
child: Text(confirm),
|
||||
),
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
),
|
||||
if (cancel.isNotEmpty)
|
||||
Button(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 2, bottom: 2, left: 8, right: 8),
|
||||
child: Text(cancel),
|
||||
),
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
),
|
||||
],
|
||||
constraints: constraints);
|
||||
final r = await showBaseDialog(
|
||||
context,
|
||||
title: title,
|
||||
content: content,
|
||||
actions: [
|
||||
if (confirm.isNotEmpty)
|
||||
FilledButton(
|
||||
child: Padding(padding: const EdgeInsets.only(top: 2, bottom: 2, left: 8, right: 8), child: Text(confirm)),
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
),
|
||||
if (cancel.isNotEmpty)
|
||||
Button(
|
||||
child: Padding(padding: const EdgeInsets.only(top: 2, bottom: 2, left: 8, right: 8), child: Text(cancel)),
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
),
|
||||
],
|
||||
constraints: constraints,
|
||||
);
|
||||
return r == true;
|
||||
}
|
||||
|
||||
Future<String?> showInputDialogs(BuildContext context,
|
||||
{required String title,
|
||||
required String content,
|
||||
BoxConstraints? constraints,
|
||||
String? initialValue,
|
||||
List<TextInputFormatter>? inputFormatters}) async {
|
||||
Future<String?> showInputDialogs(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
required String content,
|
||||
BoxConstraints? constraints,
|
||||
String? initialValue,
|
||||
List<TextInputFormatter>? inputFormatters,
|
||||
}) async {
|
||||
String? userInput;
|
||||
constraints ??= BoxConstraints(maxWidth: MediaQuery
|
||||
.of(context)
|
||||
.size
|
||||
.width * .38);
|
||||
constraints ??= BoxConstraints(maxWidth: MediaQuery.of(context).size.width * .38);
|
||||
final ok = await showConfirmDialogs(
|
||||
context,
|
||||
title,
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (content.isNotEmpty)
|
||||
Text(
|
||||
content,
|
||||
style: TextStyle(color: Colors.white.withValues(alpha: .6)),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextFormBox(
|
||||
initialValue: initialValue,
|
||||
onChanged: (str) {
|
||||
userInput = str;
|
||||
},
|
||||
inputFormatters: inputFormatters,
|
||||
),
|
||||
],
|
||||
),
|
||||
constraints: constraints);
|
||||
context,
|
||||
title,
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (content.isNotEmpty) Text(content, style: TextStyle(color: Colors.white.withValues(alpha: .6))),
|
||||
const SizedBox(height: 8),
|
||||
TextFormBox(
|
||||
initialValue: initialValue,
|
||||
onChanged: (str) {
|
||||
userInput = str;
|
||||
},
|
||||
inputFormatters: inputFormatters,
|
||||
),
|
||||
],
|
||||
),
|
||||
constraints: constraints,
|
||||
);
|
||||
if (ok == true) return userInput;
|
||||
return null;
|
||||
}
|
||||
|
||||
Future showBaseDialog(BuildContext context,
|
||||
{required String title, required Widget content, List<Widget>? actions, BoxConstraints? constraints}) async {
|
||||
Future showBaseDialog(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
required Widget content,
|
||||
List<Widget>? actions,
|
||||
BoxConstraints? constraints,
|
||||
}) async {
|
||||
return await showDialog(
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
ContentDialog(
|
||||
title: Text(title),
|
||||
content: content,
|
||||
constraints: constraints ??
|
||||
const BoxConstraints(
|
||||
maxWidth: 512,
|
||||
maxHeight: 756.0,
|
||||
),
|
||||
actions: actions,
|
||||
),
|
||||
builder: (context) => ContentDialog(
|
||||
title: Text(title),
|
||||
content: content,
|
||||
constraints: constraints ?? const BoxConstraints(maxWidth: 512, maxHeight: 756.0),
|
||||
actions: actions,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user