-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
codelab_rebuild.yaml
839 lines (790 loc) · 31.2 KB
/
codelab_rebuild.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
name: FFI Generator codelab rebuild script
steps:
- name: step_03
steps:
- name: Remove step_03
rmdir: step_03
- name: Create ffigen_app
flutter: create --template=plugin_ffi --platforms=android,ios,linux,macos,windows ffigen_app
- name: Strip DEVELOPMENT_TEAM
strip-lines-containing: DEVELOPMENT_TEAM =
path: ffigen_app/example/ios/Runner.xcodeproj/project.pbxproj
- name: Remove CHANGELOG
rm: ffigen_app/CHANGELOG.md
- name: Remove LICENSE
rm: ffigen_app/LICENSE
- name: Remove README
rm: ffigen_app/README.md
- name: Add .vscode directory
mkdir: ffigen_app/.vscode
- name: Add .vscode/launch.json
path: ffigen_app/.vscode/launch.json
replace-contents: |
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "example",
"cwd": "example",
"request": "launch",
"type": "dart"
}
]
}
- name: dart format
dart: format ffigen_app
- name: dart fix ffigen_app
path: ffigen_app
dart: fix --apply
- name: dart fix ffigen_app/example
path: ffigen_app/example
dart: fix --apply
- name: dart analyze
path: ffigen_app
dart: analyze --fatal-infos
- name: Upgrade ffigen
path: ffigen_app
flutter: pub upgrade --major-versions
- name: Upgrade ffigen/example
path: ffigen_app/example
flutter: pub upgrade --major-versions
- name: Build iOS simulator bundle
path: ffigen_app/example
platforms: [ macos ]
flutter: build ios --simulator
- name: Build macOS app
path: ffigen_app/example
platforms: [ macos ]
flutter: build macos --debug
- name: Build Android app
path: ffigen_app/example
platforms: [ macos ]
flutter: build apk --debug
- name: Build Windows app
path: ffigen_app/example
platforms: [ windows ]
flutter: build windows --debug
- name: Build Linux app
path: ffigen_app/example
platforms: [ linux ]
flutter: build linux --debug
- name: Flutter clean
path: ffigen_app/example
flutter: clean
- name: Copy step_03
copydir:
from: ffigen_app
to: step_03
- name: flutter pub get step_03
path: step_03
dart: pub get
- name: step_05
steps:
- name: Remove step_05
rmdir: step_05
- name: Retrieve duktape
path: ffigen_app/src/duktape.tar.xz
retrieve-url: https://duktape.org/duktape-2.7.0.tar.xz
- name: Unarchive duktape.tar.xz with tar
platforms: [ linux, macos ]
path: ffigen_app/src
tar: xf duktape.tar.xz
- name: Unarchive duktape.tar.xz with 7z
platforms: [ windows ]
path: ffigen_app/src
7z: x duktape.tar.xz
- name: Unarchive duktape.tar with 7z
platforms: [ windows ]
path: ffigen_app/src
7z: x duktape.tar
- name: Remove duktape.tar.xz
path: ffigen_app/src
rm: duktape.tar.xz
- name: Remove duktape.tar
platforms: [ windows ]
path: ffigen_app/src
rm: duktape.tar
- name: Copy duktape-2.7.0/src/duktape.c
path: ffigen_app/src
copy:
from: duktape-2.7.0/src/duktape.c
to: duktape.c
- name: Copy duktape-2.7.0/src/duktape.h
path: ffigen_app/src
copy:
from: duktape-2.7.0/src/duktape.h
to: duktape.h
- name: Copy duktape-2.7.0/src/duk_config.h
path: ffigen_app/src
copy:
from: duktape-2.7.0/src/duk_config.h
to: duk_config.h
- name: Remove duktape-2.7.0
path: ffigen_app/src
rmdir: duktape-2.7.0
- name: Patch ffigen.yaml
path: ffigen_app/ffigen.yaml
patch-u: |
--- b/ffigen_codelab/step_05/ffigen.yaml
+++ a/ffigen_codelab/step_05/ffigen.yaml
@@ -1,15 +1,15 @@
# Run with `dart run ffigen --config ffigen.yaml`.
-name: FfigenAppBindings
+name: DuktapeBindings
description: |
- Bindings for `src/ffigen_app.h`.
+ Bindings for `src/duktape.h`.
Regenerate bindings with `dart run ffigen --config ffigen.yaml`.
-output: 'lib/ffigen_app_bindings_generated.dart'
+output: 'lib/duktape_bindings_generated.dart'
headers:
entry-points:
- - 'src/ffigen_app.h'
+ - 'src/duktape.h'
include-directives:
- - 'src/ffigen_app.h'
+ - 'src/duktape.h'
preamble: |
// ignore_for_file: always_specify_types
// ignore_for_file: camel_case_types
@@ -17,3 +17,4 @@ preamble: |
comments:
style: any
length: full
+ignore-source-errors: true
- name: Replace example/lib/main.dart
path: ffigen_app/example/lib/main.dart
replace-contents: |
// Copyright 2022 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:ffigen_app/ffigen_app.dart';
import 'package:flutter/material.dart';
const String jsCode = '1+2';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late Duktape duktape;
String output = '';
@override
void initState() {
super.initState();
duktape = Duktape();
setState(() {
output = 'Initialized Duktape';
});
}
@override
void dispose() {
duktape.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
const textStyle = TextStyle(fontSize: 25);
const spacerSmall = SizedBox(height: 10);
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Duktape Test'),
),
body: Center(
child: Container(
padding: const EdgeInsets.all(10),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
output,
style: textStyle,
textAlign: TextAlign.center,
),
spacerSmall,
ElevatedButton(
child: const Text('Run JavaScript'),
onPressed: () {
duktape.evalString(jsCode);
setState(() {
output = '$jsCode => ${duktape.getInt(-1)}';
});
},
),
],
),
),
),
),
);
}
}
- name: Replace lib/ffigen_app.dart
path: ffigen_app/lib/ffigen_app.dart
replace-contents: |
// Copyright 2022 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ffi';
import 'dart:io' show Platform;
import 'package:ffi/ffi.dart' as ffi;
import 'duktape_bindings_generated.dart';
const String _libName = 'ffigen_app';
/// The dynamic library in which the symbols for [DuktapeBindings] can be found.
final DynamicLibrary _dylib = () {
if (Platform.isMacOS || Platform.isIOS) {
return DynamicLibrary.open('$_libName.framework/$_libName');
}
if (Platform.isAndroid || Platform.isLinux) {
return DynamicLibrary.open('lib$_libName.so');
}
if (Platform.isWindows) {
return DynamicLibrary.open('$_libName.dll');
}
throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
}();
/// The bindings to the native functions in [_dylib].
final DuktapeBindings _bindings = DuktapeBindings(_dylib);
class Duktape {
Duktape() {
ctx =
_bindings.duk_create_heap(nullptr, nullptr, nullptr, nullptr, nullptr);
}
void evalString(String jsCode) {
// From duktape.h:
// #define duk_peval_string(ctx,src) \
// (duk_eval_raw((ctx), (src), 0, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
var nativeUtf8 = jsCode.toNativeUtf8();
_bindings.duk_eval_raw(
ctx,
nativeUtf8.cast<Char>(),
0,
0 /*args*/ |
DUK_COMPILE_EVAL |
DUK_COMPILE_SAFE |
DUK_COMPILE_NOSOURCE |
DUK_COMPILE_STRLEN |
DUK_COMPILE_NOFILENAME);
ffi.malloc.free(nativeUtf8);
}
int getInt(int index) {
return _bindings.duk_get_int(ctx, index);
}
void dispose() {
_bindings.duk_destroy_heap(ctx);
ctx = nullptr;
}
late Pointer<duk_hthread> ctx;
}
- name: Patch src/CMakeLists.txt
path: ffigen_app/src/CMakeLists.txt
patch-u: |
--- b/ffigen_codelab/step_05/src/CMakeLists.txt
+++ a/ffigen_codelab/step_05/src/CMakeLists.txt
@@ -6,12 +6,19 @@ cmake_minimum_required(VERSION 3.10)
project(ffigen_app_library VERSION 0.0.1 LANGUAGES C)
add_library(ffigen_app SHARED
- "ffigen_app.c"
+ duktape.c
)
set_target_properties(ffigen_app PROPERTIES
- PUBLIC_HEADER ffigen_app.h
+ PUBLIC_HEADER duktape.h
+ PRIVATE_HEADER duk_config.h
OUTPUT_NAME "ffigen_app"
)
+if (WIN32)
+set_target_properties(ffigen_app PROPERTIES
+ WINDOWS_EXPORT_ALL_SYMBOLS ON
+)
+endif (WIN32)
+
target_compile_definitions(ffigen_app PUBLIC DART_SHARED_LIB)
- name: Get deps in ffigen_app/example
path: ffigen_app/example
dart: pub get --directory .
- name: Get deps in ffigen_app
path: ffigen_app
dart: pub get --directory .
- name: Upgrade dep versions in ffigen_app/example
path: ffigen_app/example
dart: pub upgrade --major-versions --directory .
- name: Update version constraints on ffigen
path: ffigen_app
dart: pub add -d ffigen
- name: Move ffi dep from dev_deps to deps
path: ffigen_app
dart: pub add ffi
- name: flutter clean
path: ffigen_app
flutter: clean
- name: Re-get deps
path: ffigen_app
flutter: pub get
- name: Run ffigen
path: ffigen_app
dart: run ffigen --config ffigen.yaml
- name: dart analyze
path: ffigen_app
dart: analyze --fatal-infos
- name: Build Windows app
path: ffigen_app/example
platforms: [ windows ]
flutter: build windows --debug
- name: Build Linux app
path: ffigen_app/example
platforms: [ linux ]
flutter: build linux --debug
- name: Flutter clean
path: ffigen_app/example
flutter: clean
- name: Copy step_05
copydir:
from: ffigen_app
to: step_05
- name: step_06
steps:
- name: Remove step_06
rmdir: step_06
- name: Remove src/ffigen_app.c
rm: ffigen_app/src/ffigen_app.c
- name: Remove src/ffigen_app.h
rm: ffigen_app/src/ffigen_app.h
- name: Remove ios/Classes/ffigen_app.c
rm: ffigen_app/ios/Classes/ffigen_app.c
- name: Create ios/Classes/duktape.c
path: ffigen_app/ios/Classes/duktape.c
replace-contents: |
// Relative import to be able to reuse the C sources.
// See the comment in ../ffigen_app.podspec for more information.
#include "../../src/duktape.c"
- name: Remove macos/Classes/ffigen_app.c
rm: ffigen_app/macos/Classes/ffigen_app.c
- name: Create macos/Classes/duktape.c
path: ffigen_app/macos/Classes/duktape.c
replace-contents: |
// Relative import to be able to reuse the C sources.
// See the comment in ../ffigen_app.podspec for more information.
#include "../../src/duktape.c"
- name: Flutter clean
path: ffigen_app/example
flutter: clean
- name: dart analyze
path: ffigen_app
dart: analyze --fatal-infos
- name: Build iOS simulator bundle
path: ffigen_app/example
platforms: [ macos ]
flutter: build ios --simulator
- name: Build macOS app
path: ffigen_app/example
platforms: [ macos ]
flutter: build macos --debug
- name: Build Android app
path: ffigen_app/example
platforms: [ macos ]
flutter: build apk --debug
- name: Build Windows app
path: ffigen_app/example
platforms: [ windows ]
flutter: build windows --debug
- name: Build Linux app
path: ffigen_app/example
platforms: [ linux ]
flutter: build linux --debug
- name: Flutter clean
path: ffigen_app/example
flutter: clean
- name: Copy step_06
copydir:
from: ffigen_app
to: step_06
- name: step_07
steps:
- name: Remove step_07
rmdir: step_07
- name: Patch lib/ffigen_app.dart
path: ffigen_app/lib/ffigen_app.dart
patch-u: |
--- b/ffigen_codelab/step_07/lib/ffigen_app.dart
+++ a/ffigen_codelab/step_07/lib/ffigen_app.dart
@@ -5,6 +5,7 @@
import 'dart:ffi';
import 'dart:io' show Platform;
import 'package:ffi/ffi.dart' as ffi;
+import 'package:path/path.dart' as p;
import 'duktape_bindings_generated.dart';
@@ -13,12 +14,29 @@ const String _libName = 'ffigen_app';
/// The dynamic library in which the symbols for [DuktapeBindings] can be found.
final DynamicLibrary _dylib = () {
if (Platform.isMacOS || Platform.isIOS) {
+ if (Platform.environment.containsKey('FLUTTER_TEST')) {
+ return DynamicLibrary.open(
+ 'build/macos/Build/Products/Debug/$_libName/$_libName.framework/$_libName');
+ }
return DynamicLibrary.open('$_libName.framework/$_libName');
}
if (Platform.isAndroid || Platform.isLinux) {
+ if (Platform.environment.containsKey('FLUTTER_TEST')) {
+ return DynamicLibrary.open(
+ 'build/linux/x64/debug/bundle/lib/lib$_libName.so');
+ }
return DynamicLibrary.open('lib$_libName.so');
}
if (Platform.isWindows) {
+ if (Platform.environment.containsKey('FLUTTER_TEST')) {
+ return switch (Abi.current()) {
+ Abi.windowsArm64 => DynamicLibrary.open(p.canonicalize(
+ p.join(r'build\windows\arm64\runner\Debug', '$_libName.dll'))),
+ Abi.windowsX64 => DynamicLibrary.open(p.canonicalize(
+ p.join(r'build\windows\x64\runner\Debug', '$_libName.dll'))),
+ _ => throw 'Unsupported platform',
+ };
+ }
return DynamicLibrary.open('$_libName.dll');
}
throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}');
@@ -33,13 +51,13 @@ class Duktape {
_bindings.duk_create_heap(nullptr, nullptr, nullptr, nullptr, nullptr);
}
- void evalString(String jsCode) {
+ String evalString(String jsCode) {
// From duktape.h:
// #define duk_peval_string(ctx,src) \
// (duk_eval_raw((ctx), (src), 0, 0 /*args*/ | DUK_COMPILE_EVAL | DUK_COMPILE_SAFE | DUK_COMPILE_NOSOURCE | DUK_COMPILE_STRLEN | DUK_COMPILE_NOFILENAME))
var nativeUtf8 = jsCode.toNativeUtf8();
- _bindings.duk_eval_raw(
+ final evalResult = _bindings.duk_eval_raw(
ctx,
nativeUtf8.cast<Char>(),
0,
@@ -50,10 +68,21 @@ class Duktape {
DUK_COMPILE_STRLEN |
DUK_COMPILE_NOFILENAME);
ffi.malloc.free(nativeUtf8);
+
+ if (evalResult != 0) {
+ throw _retrieveTopOfStackAsString();
+ }
+
+ return _retrieveTopOfStackAsString();
}
- int getInt(int index) {
- return _bindings.duk_get_int(ctx, index);
+ String _retrieveTopOfStackAsString() {
+ Pointer<Size> outLengthPtr = ffi.calloc<Size>();
+ final errorStrPtr = _bindings.duk_safe_to_lstring(ctx, -1, outLengthPtr);
+ final returnVal =
+ errorStrPtr.cast<ffi.Utf8>().toDartString(length: outLengthPtr.value);
+ ffi.calloc.free(outLengthPtr);
+ return returnVal;
}
void dispose() {
- name: Create example/lib/duktape_message.dart
path: ffigen_app/example/lib/duktape_message.dart
replace-contents: |
// Copyright 2022 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:freezed_annotation/freezed_annotation.dart';
part 'duktape_message.freezed.dart';
@freezed
class DuktapeMessage with _$DuktapeMessage {
factory DuktapeMessage.evaluate(String code) = DuktapeMessageCode;
factory DuktapeMessage.response(String result) = DuktapeMessageResponse;
factory DuktapeMessage.error(String log) = DuktapeMessageError;
}
- name: Replace example/lib/main.dart
path: ffigen_app/example/lib/main.dart
replace-contents: |
// Copyright 2017, 2020, 2022 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.
import 'package:ffigen_app/ffigen_app.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';
import 'duktape_message.dart';
void main() {
runApp(const ProviderScope(child: DuktapeApp()));
}
final duktapeMessagesProvider =
StateNotifierProvider<DuktapeMessageNotifier, List<DuktapeMessage>>((ref) {
return DuktapeMessageNotifier(messages: <DuktapeMessage>[]);
});
class DuktapeMessageNotifier extends StateNotifier<List<DuktapeMessage>> {
DuktapeMessageNotifier({required List<DuktapeMessage> messages})
: duktape = Duktape(),
super(messages);
final Duktape duktape;
void eval(String code) {
state = [
DuktapeMessage.evaluate(code),
...state,
];
try {
final response = duktape.evalString(code);
state = [
DuktapeMessage.response(response),
...state,
];
} catch (e) {
state = [
DuktapeMessage.error('$e'),
...state,
];
}
}
}
class DuktapeApp extends StatelessWidget {
const DuktapeApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Duktape App',
home: DuktapeRepl(),
);
}
}
class DuktapeRepl extends ConsumerStatefulWidget {
const DuktapeRepl({
super.key,
});
@override
ConsumerState<DuktapeRepl> createState() => _DuktapeReplState();
}
class _DuktapeReplState extends ConsumerState<DuktapeRepl> {
final _controller = TextEditingController();
final _focusNode = FocusNode();
var _isComposing = false;
void _handleSubmitted(String text) {
_controller.clear();
setState(() {
_isComposing = false;
});
setState(() {
ref.read(duktapeMessagesProvider.notifier).eval(text);
});
_focusNode.requestFocus();
}
@override
Widget build(BuildContext context) {
final messages = ref.watch(duktapeMessagesProvider);
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: const Text('Duktape REPL'),
elevation: Theme.of(context).platform == TargetPlatform.iOS ? 0.0 : 4.0,
),
body: Column(
children: [
Flexible(
child: Ink(
color: Theme.of(context).scaffoldBackgroundColor,
child: SafeArea(
bottom: false,
child: ListView.builder(
padding: const EdgeInsets.all(8.0),
reverse: true,
itemBuilder: (context, idx) => messages[idx].when(
evaluate: (str) => Padding(
padding: const EdgeInsets.symmetric(vertical: 2),
child: Text(
'> $str',
style: GoogleFonts.firaCode(
textStyle: Theme.of(context).textTheme.titleMedium,
),
),
),
response: (str) => Padding(
padding: const EdgeInsets.symmetric(vertical: 2),
child: Text(
'= $str',
style: GoogleFonts.firaCode(
textStyle: Theme.of(context).textTheme.titleMedium,
color: Colors.blue[800],
),
),
),
error: (str) => Padding(
padding: const EdgeInsets.symmetric(vertical: 2),
child: Text(
str,
style: GoogleFonts.firaCode(
textStyle: Theme.of(context).textTheme.titleSmall,
color: Colors.red[800],
fontWeight: FontWeight.bold,
),
),
),
),
itemCount: messages.length,
),
),
),
),
const Divider(height: 1.0),
SafeArea(
top: false,
child: Container(
decoration: BoxDecoration(color: Theme.of(context).cardColor),
child: _buildTextComposer(),
),
),
],
),
);
}
Widget _buildTextComposer() {
return IconTheme(
data: IconThemeData(color: Theme.of(context).colorScheme.secondary),
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 8.0),
child: Row(
children: [
Text('>', style: Theme.of(context).textTheme.titleMedium),
const SizedBox(width: 4),
Flexible(
child: TextField(
controller: _controller,
decoration: const InputDecoration(
border: InputBorder.none,
),
onChanged: (text) {
setState(() {
_isComposing = text.isNotEmpty;
});
},
onSubmitted: _isComposing ? _handleSubmitted : null,
focusNode: _focusNode,
),
),
Container(
margin: const EdgeInsets.symmetric(horizontal: 4.0),
child: IconButton(
icon: const Icon(Icons.send),
onPressed: _isComposing
? () => _handleSubmitted(_controller.text)
: null,
),
),
],
),
),
);
}
}
- name: mkdir example/test
path: ffigen_app
mkdir: example/test
- name: Create example/test/widget_test.dart
path: ffigen_app/example/test/widget_test.dart
replace-contents: |
import 'package:ffigen_app/ffigen_app.dart';
import 'package:ffigen_app_example/main.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('DuktapeApp displays the title', (tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const ProviderScope(child: DuktapeApp()));
// Verify that our app displays the title
expect(find.text('Duktape REPL'), findsOneWidget);
});
test('Duktape.evalString', () {
final duktape = Duktape();
final response = duktape.evalString('1+2');
expect(response, '3');
});
}
- name: Patch example/macos/Runner/DebugProfile.entitlements
path: ffigen_app/example/macos/Runner/DebugProfile.entitlements
patch-u: |
diff --git b/ffigen_codelab/step_07/example/macos/Runner/DebugProfile.entitlements a/ffigen_codelab/step_07/example/macos/Runner/DebugProfile.entitlements
index dddb8a30..08c3ab17 100644
--- b/ffigen_codelab/step_07/example/macos/Runner/DebugProfile.entitlements
+++ a/ffigen_codelab/step_07/example/macos/Runner/DebugProfile.entitlements
@@ -8,5 +8,7 @@
<true/>
<key>com.apple.security.network.server</key>
<true/>
+ <key>com.apple.security.network.client</key>
+ <true/>
</dict>
</plist>
- name: Patch example/macos/Runner/Release.entitlements
path: ffigen_app/example/macos/Runner/Release.entitlements
patch-u: |
diff --git b/ffigen_codelab/step_07/example/macos/Runner/Release.entitlements a/ffigen_codelab/step_07/example/macos/Runner/Release.entitlements
index 852fa1a4..ee95ab7e 100644
--- b/ffigen_codelab/step_07/example/macos/Runner/Release.entitlements
+++ a/ffigen_codelab/step_07/example/macos/Runner/Release.entitlements
@@ -4,5 +4,7 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
+ <key>com.apple.security.network.client</key>
+ <true/>
</dict>
</plist>
- name: Flutter clean
path: ffigen_app/example
flutter: clean
- name: Add path
path: ffigen_app
dart: pub add path
- name: Add flutter_riverpod freezed_annotation google_fonts
path: ffigen_app/example
dart: pub add flutter_riverpod freezed_annotation google_fonts
- name: Add build_runner freezed
path: ffigen_app/example
dart: pub add -d build_runner freezed
- name: flutter clean
path: ffigen_app/example
flutter: clean
- name: build runner
path: ffigen_app/example
dart: run build_runner build --delete-conflicting-outputs
- name: dart analyze
path: ffigen_app
dart: analyze --fatal-infos
- name: Build iOS simulator bundle
path: ffigen_app/example
platforms: [ macos ]
flutter: build ios --simulator
- name: Build macOS app
path: ffigen_app/example
platforms: [ macos ]
flutter: build macos --debug
- name: Test macOS bundle
path: ffigen_app/example
platforms: [ macos ]
flutter: test
- name: Build Android app
path: ffigen_app/example
platforms: [ macos ]
flutter: build apk --debug
- name: Build Windows app
path: ffigen_app/example
platforms: [ windows ]
flutter: build windows --debug
- name: Build Linux app
path: ffigen_app/example
platforms: [ linux ]
flutter: build linux --debug
- name: Flutter clean
path: ffigen_app/example
flutter: clean
- name: Copy step_07
copydir:
from: ffigen_app
to: step_07
- name: Cleanup ffigen_app
rmdir: ffigen_app