-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
943 additions
and
575 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:alga/tools/formatters/dart/dart_format.provider.dart'; | ||
import 'package:alga/ui/widgets/error_message_expandable.dart'; | ||
import 'package:alga/ui/widgets/scaffold/tool_actions.dart'; | ||
import 'package:alga/ui/widgets/scaffold/tool_copy.dart'; | ||
import 'package:alga/ui/widgets/scaffold/tool_scaffold.dart'; | ||
import 'package:alga/utils/constants/import_helper.dart'; | ||
|
||
class DartFormatView extends ConsumerStatefulWidget { | ||
const DartFormatView({super.key}); | ||
|
||
@override | ||
ConsumerState<ConsumerStatefulWidget> createState() => _DartFormatViewState(); | ||
} | ||
|
||
class _DartFormatViewState extends ConsumerState<DartFormatView> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return ToolScaffold( | ||
title: Text(context.tr.formatterDart), | ||
body: ToolActions( | ||
childExpanded: true, | ||
actions: [ | ||
if (ref.watch(dartFormatLoadingProvider)) | ||
const CircularProgressIndicator.adaptive(), | ||
const Spacer(), | ||
ToolCopy.icon(ref.watch(dartContentProvider)), | ||
FilledButton.tonalIcon( | ||
onPressed: () { | ||
ref.read(dartContentProvider.notifier).format(); | ||
}, | ||
icon: const Icon(Icons.format_indent_decrease_rounded), | ||
label: Text(context.tr.format), | ||
), | ||
], | ||
child: TextField( | ||
expands: true, | ||
minLines: null, | ||
maxLines: null, | ||
textAlignVertical: TextAlignVertical.top, | ||
controller: ref.watch(dartContentProvider), | ||
decoration: InputDecoration( | ||
error: ErrorMessageWidget.get(ref.watch(errorMessageProvider)), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import 'package:alga/utils/constants/import_helper.dart'; | ||
import 'package:dart_style/dart_style.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
part 'dart_format.provider.g.dart'; | ||
|
||
@riverpod | ||
class DartFormatLoading extends _$DartFormatLoading { | ||
@override | ||
bool build() => false; | ||
|
||
update(bool value) => state = value; | ||
} | ||
|
||
@riverpod | ||
class ErrorMessage extends _$ErrorMessage { | ||
@override | ||
String? build() => null; | ||
void update(String? value) => state = value; | ||
} | ||
|
||
@riverpod | ||
class DartContent extends _$DartContent { | ||
@override | ||
Raw<RichTextController> build() { | ||
final controller = RichTextController.lang(type: HighlightType.dart); | ||
ref.onDispose(controller.dispose); | ||
return controller; | ||
} | ||
|
||
FutureOr format() async { | ||
try { | ||
final text = state.text; | ||
if (text.length > 2000) { | ||
state.text = _format(text); | ||
} else { | ||
ref.read(dartFormatLoadingProvider.notifier).update(true); | ||
state.text = await compute(_format, text); | ||
} | ||
} catch (e) { | ||
ref.read(errorMessageProvider.notifier).update(e.toString()); | ||
} finally { | ||
ref.read(dartFormatLoadingProvider.notifier).update(false); | ||
} | ||
} | ||
} | ||
|
||
String _format(String text) { | ||
return DartFormatter().format(text); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
lib/tools/formatters/dart_formatter/dart_formatter_view.dart
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.