@@ -69,7 +69,7 @@ from the FFIgen README for more details.
6969First, add ` package:ffigen ` as a dev dependency:
7070
7171``` console
72- $ dart pub add -- dev ffigen
72+ $ dart pub add dev: ffigen
7373```
7474
7575Then, configure FFIgen to generate bindings for the
@@ -137,7 +137,7 @@ FFIgen sometimes generates a `.m` file,
137137containing Objective-C code required for interop with the API.
138138FFIgen generates this file only if the API requires it
139139(for example, if you're using blocks or protocols).
140- By default this file will have the same name as the Dart bindings,
140+ By default, this file has the same name as the Dart bindings,
141141but with ` .m ` at the end of the file name.
142142You can change its location with the ` output.objectiveCFile ` option.
143143If FFIgen produces this file, you must compile it into your package,
@@ -216,8 +216,8 @@ check out the [FFIgen API documentation][].
216216
217217### Generate the Objective-C bindings
218218
219- To generate the bindings, navigate to the example directory,
220- and run the script:
219+ To generate the bindings,
220+ navigate to the ` example ` directory and run the script:
221221
222222``` console
223223$ dart run generate_code.dart
@@ -272,16 +272,16 @@ that handles this conversion,
272272and a ` toDartString() ` method that converts it back to a Dart ` String ` .
273273
274274``` dart
275- for (final file in args) {
276- final fileStr = NSString(file);
277- print('Loading $file');
275+ for (final file in args) {
276+ final fileStr = NSString(file);
277+ print('Loading $file');
278278```
279279
280280The audio player expects an ` NSURL ` , so next,
281281use the [ ` fileURLWithPath: ` ] [ ] method to convert the ` NSString ` to an ` NSURL ` .
282282
283283``` dart
284- final fileUrl = NSURL.fileURLWithPath(fileStr);
284+ final fileUrl = NSURL.fileURLWithPath(fileStr);
285285```
286286
287287Now, you can construct the ` AVAudioPlayer ` .
@@ -295,10 +295,10 @@ To initialize the `AVAudioPlayer`,
295295use the [ ` initWithContentsOfURL:error: ` ] [ ] method:
296296
297297``` dart
298- final player = AVAudioPlayer.alloc().initWithContentsOfURL(
299- fileUrl,
300- error: nullptr,
301- );
298+ final player = AVAudioPlayer.alloc().initWithContentsOfURL(
299+ fileUrl,
300+ error: nullptr,
301+ );
302302```
303303
304304This Dart ` AVAudioPlayer ` object is a wrapper around an underlying
@@ -323,21 +323,21 @@ so you can immediately use the Dart `.ceil()` method
323323to round up to the next second:
324324
325325``` dart
326- final durationSeconds = player.duration.ceil();
327- print('$durationSeconds sec');
326+ final durationSeconds = player.duration.ceil();
327+ print('$durationSeconds sec');
328328```
329329
330330Finally, you can use the [ ` play ` ] [ ] method to play the audio,
331331then check the status, and wait for the duration of the audio file:
332332
333333``` dart
334- final status = player.play();
335- if (status) {
336- print('Playing...');
337- await Future<void>.delayed(Duration(seconds: durationSeconds));
338- } else {
339- print('Failed to play audio.');
340- }
334+ final status = player.play();
335+ if (status) {
336+ print('Playing...');
337+ await Future<void>.delayed(Duration(seconds: durationSeconds));
338+ } else {
339+ print('Failed to play audio.');
340+ }
341341```
342342
343343[ play_audio.dart ] : {{page.example}}/play_audio.dart
@@ -351,10 +351,10 @@ This stems from differences between Dart isolates and OS threads,
351351and how Apple's APIs handle concurrency:
352352
3533531 . Dart isolates aren't the same thing as threads.
354- Isolates run on threads,
355- but aren't guaranteed to run on any particular thread,
356- and the VM might change which thread an isolate is running on
357- without warning.
354+ Isolates run on threads but aren't
355+ 2 . guaranteed to run on any particular thread,
356+ and the VM might change which thread an isolate is
357+ running on without warning.
358358 There is an [ open feature request] [ ] to enable isolates to be
359359 pinned to specific threads.
3603602 . While FFIgen supports converting
@@ -385,7 +385,7 @@ add support for non-`void` return values in the future.
385385
386386The third point means that directly calling some Apple APIs
387387using the generated Dart bindings might be thread unsafe.
388- This could crash your app, or cause other unpredictable behavior.
388+ This could crash your app or cause other unpredictable behavior.
389389In recent versions of Flutter, the main isolate runs on the platform thread,
390390so this isn't an issue when invoking these thread-locked APIs
391391from the main isolate.
@@ -462,7 +462,7 @@ and generates a wrapper header, `swift_api.h`.
462462It also generates the dylib you're going to load later,
463463` libswiftapi.dylib ` .
464464
465- You can verify that the header generated correctly by opening it,
465+ You can verify that the header generated correctly by opening it
466466and checking that the interfaces are what you expect.
467467Towards the bottom of the file,
468468you should see something like the following:
@@ -476,7 +476,7 @@ SWIFT_CLASS("_TtC12swift_module10SwiftClass")
476476@end
477477```
478478
479- If the interface is missing, or doesn't have all its methods,
479+ If the interface is missing, or doesn't have all of its methods,
480480make sure they're all annotated with `@objc` and `public`.
481481
482482### Configuring FFIgen for Swift
@@ -556,8 +556,8 @@ This outputs `swift_module.SwiftClass`.
556556
557557### Generating the Swift bindings
558558
559- As before, navigate to the example directory ,
560- and run FFIgen:
559+ As before, to generate the bindings ,
560+ navigate to the example directory and run FFIgen:
561561
562562``` console
563563$ dart run ffigen
@@ -586,7 +586,7 @@ void main() {
586586
587587Note that the module name is not mentioned
588588in the generated Dart API.
589- It's only used internally,
589+ It's only used internally
590590to load the class from the dylib.
591591
592592Now you can run the example using:
0 commit comments