Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow inject a dio instance #104

Merged
merged 2 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions docs/docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ void main() async {
}
```

You can also specify your custom Parsers in `Mirai.initialize`.
You can also specify your custom Parsers in `Mirai.initialize` and `Dio` instance.

```dart
void main() async {
await Mirai.initialize(parsers: const [
ExampleScreenParser(),
]);
final dio = Dio()

await Mirai.initialize(
parsers: const [
ExampleScreenParser(),
],
dio: dio,
);
divyanshub024 marked this conversation as resolved.
Show resolved Hide resolved

runApp(const MyApp());
}
Expand Down
2 changes: 2 additions & 0 deletions packages/mirai/lib/src/framework/mirai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ class Mirai {

static Future<void> initialize({
List<MiraiParser> parsers = const [],
Dio? dio,
}) async {
_parsers.addAll(parsers);
MiraiRegistry.instance.registerAll(_parsers);
MiraiNetwork.initialize(dio ?? Dio());
}

static Widget? fromJson(Map<String, dynamic>? json, BuildContext context) {
Expand Down
4 changes: 3 additions & 1 deletion packages/mirai/lib/src/network/mirai_network.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import 'package:mirai/src/network/mirai_request.dart';
class MiraiNetwork {
const MiraiNetwork._();

static final _dio = Dio();
static late Dio _dio;

static void initialize(Dio dio) => _dio = dio;

static Future<Response?> request(MiraiRequest request) {
switch (request.method) {
Expand Down