mirror of
https://github.com/jagandeepbrar/lunasea.git
synced 2026-08-31 20:52:32 +00:00
* chore(packages): Added pedantic package to enforce linting and styling * feat(lunasea): Enforce effective dart styling * Comment and format colours class * Localize additional classes in Dashboard, cleanup additional code * chore(lunasea): Major refactor by running dartfmt on the entire codebase, added widget return for page routers * Additional work on conforming to effective dart style * fix(share_plus): Roll back share_plus package to 2.0.0 to support iOS 12 or lower * chore(lunasea): Fix remaining enabled analysis warnings
155 lines
4.7 KiB
Dart
155 lines
4.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:lunasea/core.dart';
|
|
|
|
class LunaDialogs {
|
|
/// Show an an edit text prompt.
|
|
///
|
|
/// Can pass in [prefill] String to prefill the [TextFormField]. Can also pass in a list of [TextSpan] tp show text above the field.
|
|
///
|
|
/// Returns list containing:
|
|
/// - 0: Flag (true if they hit save, false if they cancelled the prompt)
|
|
/// - 1: Value from the [TextEditingController].
|
|
Future<Tuple2<bool, String>> editText(
|
|
BuildContext context, String dialogTitle,
|
|
{String prefill = '', List<TextSpan> extraText}) async {
|
|
bool _flag = false;
|
|
final _formKey = GlobalKey<FormState>();
|
|
final _textController = TextEditingController()..text = prefill;
|
|
|
|
void _setValues(bool flag) {
|
|
if (_formKey.currentState.validate()) {
|
|
_flag = flag;
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
}
|
|
}
|
|
|
|
await LunaDialog.dialog(
|
|
context: context,
|
|
title: dialogTitle,
|
|
buttons: [
|
|
LunaDialog.button(
|
|
text: 'Save',
|
|
onPressed: () => _setValues(true),
|
|
),
|
|
],
|
|
content: [
|
|
if ((extraText?.length ?? 0) != 0)
|
|
LunaDialog.richText(children: extraText),
|
|
Form(
|
|
key: _formKey,
|
|
child: LunaDialog.textFormInput(
|
|
controller: _textController,
|
|
title: dialogTitle,
|
|
onSubmitted: (_) => _setValues(true),
|
|
validator: (_) => null,
|
|
),
|
|
),
|
|
],
|
|
contentPadding: (extraText?.length ?? 0) == 0
|
|
? LunaDialog.inputDialogContentPadding()
|
|
: LunaDialog.inputTextDialogContentPadding(),
|
|
);
|
|
return Tuple2(_flag, _textController.text);
|
|
}
|
|
|
|
/// Show a text preview dialog.
|
|
///
|
|
/// Can pass in boolean [alignLeft] to left align the text in the dialog (useful for bulleted lists)
|
|
Future<void> textPreview(
|
|
BuildContext context, String dialogTitle, String text,
|
|
{bool alignLeft = false}) async {
|
|
await LunaDialog.dialog(
|
|
context: context,
|
|
title: dialogTitle,
|
|
cancelButtonText: 'Close',
|
|
buttons: [
|
|
LunaDialog.button(
|
|
text: 'Copy',
|
|
onPressed: () async {
|
|
await Clipboard.setData(ClipboardData(text: text));
|
|
showLunaSuccessSnackBar(
|
|
title: 'Copied Content',
|
|
message: 'Copied text to the clipboard');
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
}),
|
|
],
|
|
content: [
|
|
LunaDialog.textContent(text: text),
|
|
],
|
|
contentPadding: LunaDialog.textDialogContentPadding(),
|
|
);
|
|
}
|
|
|
|
Future<void> showRejections(
|
|
BuildContext context, List<String> rejections) async {
|
|
if ((rejections ?? []).isEmpty)
|
|
return textPreview(context, 'Rejection Reasons', 'No rejections found');
|
|
await LunaDialog.dialog(
|
|
context: context,
|
|
title: 'Rejection Reasons',
|
|
cancelButtonText: 'Close',
|
|
content: List.generate(
|
|
rejections.length,
|
|
(index) => LunaDialog.tile(
|
|
text: rejections[index],
|
|
icon: Icons.report_outlined,
|
|
iconColor: LunaColours.red,
|
|
),
|
|
),
|
|
contentPadding: LunaDialog.listDialogContentPadding(),
|
|
);
|
|
}
|
|
|
|
Future<void> showMessages(BuildContext context, List<String> messages) async {
|
|
if ((messages ?? []).isEmpty)
|
|
return textPreview(context, 'Messages', 'No messages found');
|
|
await LunaDialog.dialog(
|
|
context: context,
|
|
title: 'Messages',
|
|
cancelButtonText: 'Close',
|
|
content: List.generate(
|
|
messages.length,
|
|
(index) => LunaDialog.tile(
|
|
text: messages[index],
|
|
icon: Icons.info_outline_rounded,
|
|
iconColor: LunaColours.accent,
|
|
),
|
|
),
|
|
contentPadding: LunaDialog.listDialogContentPadding(),
|
|
);
|
|
}
|
|
|
|
/// **Will be removed in future**
|
|
///
|
|
/// Show a delete catalogue with all files warning dialog.
|
|
Future<List<dynamic>> deleteCatalogueWithFiles(
|
|
BuildContext context, String moduleTitle) async {
|
|
bool _flag = false;
|
|
|
|
void _setValues(bool flag) {
|
|
_flag = flag;
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
}
|
|
|
|
await LunaDialog.dialog(
|
|
context: context,
|
|
title: 'Delete All Files',
|
|
buttons: [
|
|
LunaDialog.button(
|
|
text: 'Delete',
|
|
textColor: LunaColours.red,
|
|
onPressed: () => _setValues(true),
|
|
),
|
|
],
|
|
content: [
|
|
LunaDialog.textContent(
|
|
text:
|
|
'Are you sure you want to delete all the files and folders for $moduleTitle?'),
|
|
],
|
|
contentPadding: LunaDialog.textDialogContentPadding(),
|
|
);
|
|
return [_flag];
|
|
}
|
|
}
|