Skip to content

Commit 0a7b723

Browse files
committed
🎨 style: format code with dart formatter
应用 dart format 自动格式化,调整代码风格以符 Dart 规范。 受影响文件: - example/lib/app/home_screen.dart - example/lib/screens/*.dart(6 个屏幕文件) - example/lib/services/*.dart(3 个服务文件) - example/lib/widgets/*.dart(2 个组件文件) - example/integration_test/simple_test.dart - example/pubspec.lock(依赖锁定文件)
1 parent fba176c commit 0a7b723

15 files changed

Lines changed: 402 additions & 256 deletions

example/integration_test/simple_test.dart

Lines changed: 134 additions & 65 deletions
Large diffs are not rendered by default.

example/lib/app/home_screen.dart

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ class _HomeScreenState extends State<HomeScreen> {
178178
Text(
179179
'FJS',
180180
style: Theme.of(context).textTheme.labelSmall?.copyWith(
181-
fontWeight: FontWeight.bold,
182-
),
181+
fontWeight: FontWeight.bold,
182+
),
183183
),
184184
],
185185
),
@@ -296,7 +296,8 @@ class _HomeScreenState extends State<HomeScreen> {
296296
}
297297
}
298298

299-
PreferredSizeWidget _buildAppBar(BuildContext context, {bool showDrawer = true}) {
299+
PreferredSizeWidget _buildAppBar(BuildContext context,
300+
{bool showDrawer = true}) {
300301
return AppBar(
301302
title: const Text('FJS JavaScript Runtime'),
302303
automaticallyImplyLeading: showDrawer,
@@ -400,15 +401,18 @@ class _HomeScreenState extends State<HomeScreen> {
400401
Text(
401402
'FJS',
402403
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
403-
color: Theme.of(context).colorScheme.onPrimary,
404-
fontWeight: FontWeight.bold,
405-
),
404+
color: Theme.of(context).colorScheme.onPrimary,
405+
fontWeight: FontWeight.bold,
406+
),
406407
),
407408
Text(
408409
'Flutter JavaScript Runtime',
409410
style: Theme.of(context).textTheme.bodySmall?.copyWith(
410-
color: Theme.of(context).colorScheme.onPrimary.withValues(alpha: 0.8),
411-
),
411+
color: Theme.of(context)
412+
.colorScheme
413+
.onPrimary
414+
.withValues(alpha: 0.8),
415+
),
412416
),
413417
],
414418
),
@@ -617,7 +621,8 @@ class _HomeScreenState extends State<HomeScreen> {
617621
label: const Text('API Docs'),
618622
),
619623
FilledButton.tonalIcon(
620-
onPressed: () => Navigator.pushNamed(context, '/js-actions-test'),
624+
onPressed: () =>
625+
Navigator.pushNamed(context, '/js-actions-test'),
621626
icon: const Icon(Icons.science),
622627
label: const Text('Run Tests'),
623628
),
@@ -653,7 +658,8 @@ class _HomeScreenState extends State<HomeScreen> {
653658
const SizedBox(height: 12),
654659
CodeEditorWidget(
655660
controller: _codeController,
656-
hintText: '// Enter your JavaScript code here...\nconsole.log("Hello, FJS!");',
661+
hintText:
662+
'// Enter your JavaScript code here...\nconsole.log("Hello, FJS!");',
657663
height: 200,
658664
isLoading: _isExecuting,
659665
),
@@ -717,7 +723,9 @@ class _HomeScreenState extends State<HomeScreen> {
717723
),
718724
const SizedBox(height: 12),
719725
ResultDisplayWidget(
720-
result: _result.isNotEmpty && !_result.startsWith('Error:') ? _result : null,
726+
result: _result.isNotEmpty && !_result.startsWith('Error:')
727+
? _result
728+
: null,
721729
error: _result.startsWith('Error:') ? _result : null,
722730
isLoading: _isExecuting,
723731
height: 200,
@@ -753,7 +761,8 @@ class _HomeScreenState extends State<HomeScreen> {
753761
),
754762
const SizedBox(height: 12),
755763
...JsExampleCategory.values.take(4).map((category) {
756-
final examples = examplesService.getExamplesByCategory(category);
764+
final examples =
765+
examplesService.getExamplesByCategory(category);
757766
if (examples.isEmpty) return const SizedBox.shrink();
758767

759768
return Column(
@@ -771,10 +780,13 @@ class _HomeScreenState extends State<HomeScreen> {
771780
Wrap(
772781
spacing: 8,
773782
runSpacing: 8,
774-
children: examples.take(4).map((example) => ActionChip(
775-
label: Text(example.label),
776-
onPressed: () => _loadExample(example),
777-
)).toList(),
783+
children: examples
784+
.take(4)
785+
.map((example) => ActionChip(
786+
label: Text(example.label),
787+
onPressed: () => _loadExample(example),
788+
))
789+
.toList(),
778790
),
779791
const SizedBox(height: 12),
780792
],
@@ -789,7 +801,8 @@ class _HomeScreenState extends State<HomeScreen> {
789801
}
790802

791803
Future<void> _loadExample(JsExample example) async {
792-
final examplesService = Provider.of<JsExamplesService>(context, listen: false);
804+
final examplesService =
805+
Provider.of<JsExamplesService>(context, listen: false);
793806
final code = await examplesService.loadExampleCode(example.fileName);
794807
if (code != null) {
795808
_codeController.text = code;

example/lib/screens/api_overview_screen.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -260,17 +260,20 @@ class ApiOverviewScreen extends StatelessWidget {
260260
Wrap(
261261
spacing: 6,
262262
runSpacing: 6,
263-
children: api.features.map((f) => Container(
264-
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
265-
decoration: BoxDecoration(
266-
color: theme.colorScheme.surfaceContainerHighest,
267-
borderRadius: BorderRadius.circular(4),
268-
),
269-
child: Text(
270-
f,
271-
style: theme.textTheme.labelSmall,
272-
),
273-
)).toList(),
263+
children: api.features
264+
.map((f) => Container(
265+
padding: const EdgeInsets.symmetric(
266+
horizontal: 8, vertical: 4),
267+
decoration: BoxDecoration(
268+
color: theme.colorScheme.surfaceContainerHighest,
269+
borderRadius: BorderRadius.circular(4),
270+
),
271+
child: Text(
272+
f,
273+
style: theme.textTheme.labelSmall,
274+
),
275+
))
276+
.toList(),
274277
),
275278
],
276279
),

example/lib/screens/engine_api_screen.dart

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import 'package:fjs/fjs.dart';
32
import 'package:flutter/foundation.dart';
43
import 'package:flutter/material.dart';
@@ -43,7 +42,8 @@ class _EngineApiScreenState extends State<EngineApiScreen> {
4342
if (kDebugMode) {
4443
print('Bridge call received: ${value.value}');
4544
}
46-
return JsResult.ok(JsValue.string('Response from Dart: ${value.value}'));
45+
return JsResult.ok(
46+
JsValue.string('Response from Dart: ${value.value}'));
4747
},
4848
);
4949
setState(() => _isInitialized = true);
@@ -157,7 +157,8 @@ class _EngineApiScreenState extends State<EngineApiScreen> {
157157
color: _isInitialized ? Colors.green.shade50 : Colors.orange.shade50,
158158
borderRadius: BorderRadius.circular(12),
159159
border: Border.all(
160-
color: _isInitialized ? Colors.green.shade200 : Colors.orange.shade200,
160+
color:
161+
_isInitialized ? Colors.green.shade200 : Colors.orange.shade200,
161162
),
162163
),
163164
child: Row(
@@ -283,19 +284,20 @@ class _EngineApiScreenState extends State<EngineApiScreen> {
283284
error: _testResults['eval_options']?.error,
284285
onRun: () => _runTest('eval_options', () async {
285286
if (_engine == null) throw 'Engine not initialized';
286-
287+
287288
// Test with strict mode
288289
final strictResult = await _engine!.eval(
289290
source: JsCode.code('"use strict"; let x = 10; x * 2'),
290291
options: JsEvalOptions(strict: true),
291292
);
292-
293+
293294
// Test with global scope
294295
final globalResult = await _engine!.eval(
295-
source: JsCode.code('globalThis.myGlobal = 42; globalThis.myGlobal'),
296+
source:
297+
JsCode.code('globalThis.myGlobal = 42; globalThis.myGlobal'),
296298
options: JsEvalOptions(global: true),
297299
);
298-
300+
299301
return {
300302
'strictMode': {
301303
'result': strictResult.value,
@@ -345,19 +347,21 @@ class _EngineApiScreenState extends State<EngineApiScreen> {
345347
error: _testResults['eval_complex']?.error,
346348
onRun: () => _runTest('eval_complex', () async {
347349
if (_engine == null) throw 'Engine not initialized';
348-
350+
349351
final expressions = {
350352
'math': 'Math.sqrt(16) + Math.pow(2, 3)',
351353
'string': '"Hello".split("").reverse().join("")',
352354
'array': '[1,2,3].map(x => x * 2).filter(x => x > 2)',
353-
'object': '({name: "FJS", version: "1.0", features: ["fast", "safe"]})',
355+
'object':
356+
'({name: "FJS", version: "1.0", features: ["fast", "safe"]})',
354357
'date': 'new Date().toISOString()',
355358
'json': 'JSON.stringify({a: 1, b: [2, 3]})',
356359
};
357-
360+
358361
final results = <String, dynamic>{};
359362
for (final entry in expressions.entries) {
360-
final result = await _engine!.eval(source: JsCode.code(entry.value));
363+
final result =
364+
await _engine!.eval(source: JsCode.code(entry.value));
361365
results[entry.key] = {
362366
'expression': entry.value,
363367
'result': result.value,
@@ -408,21 +412,21 @@ class _EngineApiScreenState extends State<EngineApiScreen> {
408412
if (_engine == null) throw 'Engine not initialized';
409413
await _engine!.declareNewModules(
410414
modules: [
411-
JsModule(
412-
name: 'string-utils',
413-
source: JsCode.code('''
415+
JsModule(
416+
name: 'string-utils',
417+
source: JsCode.code('''
414418
export function reverse(s) { return s.split('').reverse().join(''); }
415419
export function capitalize(s) { return s.charAt(0).toUpperCase() + s.slice(1); }
416420
'''),
417-
),
418-
JsModule(
419-
name: 'array-utils',
420-
source: JsCode.code('''
421+
),
422+
JsModule(
423+
name: 'array-utils',
424+
source: JsCode.code('''
421425
export function sum(arr) { return arr.reduce((a, b) => a + b, 0); }
422426
export function unique(arr) { return [...new Set(arr)]; }
423427
'''),
424-
),
425-
],
428+
),
429+
],
426430
);
427431
return {'status': 'Modules declared: string-utils, array-utils'};
428432
}),
@@ -454,8 +458,10 @@ class _EngineApiScreenState extends State<EngineApiScreen> {
454458
error: _testResults['is_module_declared']?.error,
455459
onRun: () => _runTest('is_module_declared', () async {
456460
if (_engine == null) throw 'Engine not initialized';
457-
final exists = await _engine!.isModuleDeclared(moduleName: 'test-math');
458-
final notExists = await _engine!.isModuleDeclared(moduleName: 'non-existent');
461+
final exists =
462+
await _engine!.isModuleDeclared(moduleName: 'test-math');
463+
final notExists =
464+
await _engine!.isModuleDeclared(moduleName: 'non-existent');
459465
return {
460466
'test-math': exists,
461467
'non-existent': notExists,
@@ -498,7 +504,7 @@ class _EngineApiScreenState extends State<EngineApiScreen> {
498504
error: _testResults['use_module']?.error,
499505
onRun: () => _runTest('use_module', () async {
500506
if (_engine == null) throw 'Engine not initialized';
501-
507+
502508
// First make sure module is declared
503509
await _engine!.declareNewModule(
504510
module: JsModule(
@@ -516,7 +522,7 @@ class _EngineApiScreenState extends State<EngineApiScreen> {
516522
'''),
517523
),
518524
);
519-
525+
520526
// Then use it via dynamic import
521527
final result = await _engine!.eval(
522528
source: JsCode.code('''

example/lib/screens/error_api_screen.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ class _ErrorApiScreenState extends State<ErrorApiScreen> {
500500
onRun: () => _runTest('syntax_json', () async {
501501
if (_engine == null) throw 'Engine not initialized';
502502
try {
503-
await _engine!.eval(source: JsCode.code('JSON.parse("{invalid}")'));
503+
await _engine!
504+
.eval(source: JsCode.code('JSON.parse("{invalid}")'));
504505
return {'error': 'Expected error was not thrown'};
505506
} catch (e) {
506507
return {

example/lib/screens/example_screen.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class MyEngine {
6464

6565
Future<JsValue> evaluateModule(String taskId, String code) async {
6666
_assertInitialized();
67-
await _engine
68-
.evaluateModule(module: JsModule(name: taskId, source: JsCode.code(code)));
67+
await _engine.evaluateModule(
68+
module: JsModule(name: taskId, source: JsCode.code(code)));
6969
final result = await _engine.eval(source: JsCode.code('''
7070
(()=>{
7171
const result = globalThis['$taskId'];

0 commit comments

Comments
 (0)