Skip to content

Commit

Permalink
Merge pull request #104 from RodolfoSilva/inject-dio
Browse files Browse the repository at this point in the history
Allow inject a dio instance
  • Loading branch information
divyanshub024 authored Apr 10, 2023
2 parents 8cb8e29 + 51439d8 commit 88d7202
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
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,
);
runApp(const MyApp());
}
Expand Down
13 changes: 9 additions & 4 deletions packages/mirai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,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,
);
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

0 comments on commit 88d7202

Please sign in to comment.