diff --git a/docs/docs/overview.md b/docs/docs/overview.md index b8f05123..6e93ff4a 100644 --- a/docs/docs/overview.md +++ b/docs/docs/overview.md @@ -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()); } diff --git a/packages/mirai/README.md b/packages/mirai/README.md index 7c09333d..cd556ffd 100644 --- a/packages/mirai/README.md +++ b/packages/mirai/README.md @@ -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()); } diff --git a/packages/mirai/lib/src/framework/mirai.dart b/packages/mirai/lib/src/framework/mirai.dart index 0814f41f..5c41a835 100644 --- a/packages/mirai/lib/src/framework/mirai.dart +++ b/packages/mirai/lib/src/framework/mirai.dart @@ -55,9 +55,11 @@ class Mirai { static Future initialize({ List parsers = const [], + Dio? dio, }) async { _parsers.addAll(parsers); MiraiRegistry.instance.registerAll(_parsers); + MiraiNetwork.initialize(dio ?? Dio()); } static Widget? fromJson(Map? json, BuildContext context) { diff --git a/packages/mirai/lib/src/network/mirai_network.dart b/packages/mirai/lib/src/network/mirai_network.dart index 2dcfb023..d1984421 100644 --- a/packages/mirai/lib/src/network/mirai_network.dart +++ b/packages/mirai/lib/src/network/mirai_network.dart @@ -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 request(MiraiRequest request) { switch (request.method) {