-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #340 from cunarist/split-docs-pages
Split pages
- Loading branch information
Showing
5 changed files
with
63 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Graceful Shutdown | ||
|
||
When the Flutter app is closed, the entire `tokio` runtime on the Rust side will be terminated automatically. However, you might need to run some finalization code in Rust before the app closes. This might involve saving files or disposing of resources. To achieve this, you can call `finalizeRust()` in Dart to terminate all Rust tasks before closing the Flutter app. | ||
|
||
```dart title="lib/main.dart" | ||
import 'dart:ui'; | ||
import 'package:flutter/material.dart'; | ||
import './messages/generated.dart'; | ||
... | ||
class MyApp extends StatefulWidget { | ||
const MyApp({super.key}); | ||
@override | ||
State<MyApp> createState() => _MyAppState(); | ||
} | ||
class _MyAppState extends State<MyApp> { | ||
final _appLifecycleListener = AppLifecycleListener( | ||
onExitRequested: () async { | ||
// Terminate Rust tasks before closing the Flutter app. | ||
await finalizeRust(); | ||
return AppExitResponse.exit; | ||
}, | ||
); | ||
@override | ||
void dispose() { | ||
_appLifecycleListener.dispose(); | ||
super.dispose(); | ||
} | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'Some App', | ||
home: MyHomePage(), | ||
); | ||
} | ||
} | ||
... | ||
``` |
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,12 @@ | ||
# Printing for Debugging | ||
|
||
You might be used to `println!` macro in Rust. However, using that macro isn't a very good idea in our apps made with Flutter and Rust because `println!` outputs cannot be seen on the web and mobile emulators. | ||
|
||
When writing Rust code in the `hub` crate, you can simply print your debug message with the `debug_print!` macro provided by this framework like below. Once you use this macro, Flutter will take care of the rest. | ||
|
||
```rust title="Rust" | ||
use rinf::debug_print; | ||
debug_print!("My object is {my_object:?}"); | ||
``` | ||
|
||
`debug_print!` is also better than `println!` because it only works in debug mode, resulting in a smaller and cleaner release binary. |
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