-
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
10 changed files
with
189 additions
and
94 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,47 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
import 'package:flutter_js/flutter_js.dart'; | ||
part 'quick_js.provider.g.dart'; | ||
|
||
sealed class JsContent { | ||
const JsContent(this.value); | ||
|
||
final String value; | ||
} | ||
|
||
class InContent extends JsContent { | ||
const InContent(super.value); | ||
} | ||
|
||
class OutContent extends JsContent { | ||
const OutContent(super.value); | ||
} | ||
|
||
@Riverpod(keepAlive: true) | ||
JavascriptRuntime jsEngine(JsEngineRef ref) { | ||
return getJavascriptRuntime(); | ||
} | ||
|
||
@riverpod | ||
class JsContents extends _$JsContents { | ||
@override | ||
List<JsContent> build() => []; | ||
|
||
void exec(String content) async { | ||
final engine = ref.watch(jsEngineProvider); | ||
state = [InContent(content), ...state]; | ||
final result = await engine.evaluateAsync(content); | ||
state = [OutContent(result.stringResult), ...state]; | ||
} | ||
|
||
clear() { | ||
state = []; | ||
} | ||
} | ||
|
||
@riverpod | ||
TextEditingController jsInputController(JsInputControllerRef ref) { | ||
final controller = TextEditingController(); | ||
ref.onDispose(controller.dispose); | ||
return controller; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,56 +1,48 @@ | ||
import 'package:alga/tools/js_tools/quick_js_tool/quick_js.provider.dart'; | ||
import 'package:alga/ui/widgets/scaffold/tool_scaffold.dart'; | ||
import 'package:alga/utils/constants/import_helper.dart'; | ||
|
||
part './quick_js_provider.dart'; | ||
|
||
class QuickJsView extends StatelessWidget { | ||
class QuickJsView extends ConsumerWidget { | ||
const QuickJsView({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ScrollableToolView( | ||
title: const Text('Quick JS Tool'), | ||
children: [ | ||
AppTitleWrapper( | ||
title: S.of(context).input, | ||
actions: [ | ||
// PasteButton( | ||
// onPaste: (ref, data) { | ||
// ref.watch(_input).text = data; | ||
// return ref.refresh(_result); | ||
// }, | ||
// ), | ||
], | ||
child: const SizedBox(), | ||
// child: Consumer(builder: (context, ref, _) { | ||
// return LangTextField( | ||
// controller: ref.watch(_input), | ||
// lang: LangHighlightType.js, | ||
// minLines: 2, | ||
// maxLines: 12, | ||
// ); | ||
// }), | ||
), | ||
// Consumer(builder: (context, ref, _) { | ||
// return ElevatedButton( | ||
// onPressed: () { | ||
// return ref.refresh(_result); | ||
// }, | ||
// child: const Text('RUN'), | ||
// ); | ||
// }), | ||
AppTitleWrapper( | ||
title: S.of(context).output, | ||
actions: [ | ||
// CopyButton(onCopy: (ref) { | ||
// return ref.watch(_result); | ||
// }), | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final items = ref.watch(jsContentsProvider); | ||
return ToolScaffold( | ||
title: Text(context.tr.jsTools), | ||
body: ListView.builder( | ||
itemBuilder: (context, index) { | ||
final item = items[index]; | ||
return ListTile( | ||
title: Text(item.value), | ||
leading: item is InContent ? const Icon(Icons.arrow_right) : null, | ||
selected: item is InContent, | ||
); | ||
}, | ||
reverse: true, | ||
itemCount: items.length, | ||
), | ||
bottomNavigationBar: BottomAppBar( | ||
child: Row( | ||
children: [ | ||
Expanded( | ||
child: TextField( | ||
maxLines: 3, | ||
minLines: 1, | ||
controller: ref.watch(jsInputControllerProvider), | ||
)), | ||
IconButton( | ||
onPressed: () { | ||
final controller = ref.read(jsInputControllerProvider); | ||
final content = controller.text; | ||
controller.clear(); | ||
ref.read(jsContentsProvider.notifier).exec(content); | ||
}, | ||
icon: const Icon(Icons.rocket_launch_rounded), | ||
), | ||
], | ||
child: const SizedBox(), | ||
// child: Consumer(builder: (context, ref, _) { | ||
// return AppTextField(text: ref.watch(_result)); | ||
// }), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
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
Oops, something went wrong.