From 7f035afe5c699b2f8e7ed9e2a89b70449aee48ad Mon Sep 17 00:00:00 2001 From: Divyanshu Bhargava Date: Wed, 20 Sep 2023 14:54:01 +0400 Subject: [PATCH 01/29] Mirai FormBuilder and FormScope --- .../assets/json/example_light_theme.json | 1 - .../assets/json/sign_in_screen.json | 120 +++++++++++++ .../lib/app/home/home_screen.dart | 2 +- examples/mirai_gallery/lib/main.dart | 11 ++ examples/mirai_gallery/pubspec.lock | 2 +- examples/mirai_gallery/pubspec.yaml | 1 + packages/mirai/lib/mirai.dart | 1 - .../src/action_parsers/action_parsers.dart | 5 +- .../mirai_dialog_action.dart | 4 +- .../mirai_dialog_action.freezed.dart | 24 +-- .../mirai_dialog_action.g.dart | 3 +- .../mirai_dialog_action_parser.dart | 2 +- .../mirai_form_data/mirai_form_data.dart | 14 ++ .../mirai_form_data.freezed.dart | 151 +++++++++++++++++ .../mirai_form_data/mirai_form_data.g.dart | 17 ++ .../mirai_form_data_parser.dart | 23 +++ .../mirai_modal_bottom_sheet_action.dart | 4 +- ...rai_modal_bottom_sheet_action.freezed.dart | 24 +-- .../mirai_modal_bottom_sheet_action.g.dart | 3 +- ...irai_modal_bottom_sheet_action_parser.dart | 2 +- .../mirai_navigate_action.dart | 4 +- .../mirai_navigate_action.freezed.dart | 24 +-- .../mirai_navigate_action.g.dart | 3 +- .../mirai_navigate_action_parser.dart | 4 +- .../mirai_network_request.dart | 26 +++ .../mirai_network_request.freezed.dart} | 82 ++++----- .../mirai_network_request.g.dart} | 13 +- .../mirai_network_request_parser.dart | 27 +++ .../mirai_none_action_parser.dart | 18 -- .../mirai_request_action_parser.dart | 22 --- packages/mirai/lib/src/framework/mirai.dart | 19 ++- .../mirai/lib/src/network/mirai_network.dart | 71 -------- .../mirai/lib/src/network/mirai_request.dart | 26 --- packages/mirai/lib/src/network/network.dart | 4 - .../mirai_check_box_widget_parser.dart | 20 +-- .../mirai_form/cubit/mirai_form_cubit.dart | 99 ----------- .../mirai_form/cubit/mirai_form_state.dart | 41 ----- .../parsers/mirai_form/mirai_form_parser.dart | 79 +++++++-- .../mirai_form_field/mirai_form_field.dart | 14 -- .../mirai_form_field.freezed.dart | 160 ------------------ .../mirai_form_field/mirai_form_field.g.dart | 17 -- .../mirai_form_field_parser.dart | 35 ---- .../mirai_text_form_field_parser.dart | 37 ++-- .../src/services/mirai_network_service.dart | 106 ++++++++++++ packages/mirai/lib/src/services/services.dart | 3 + packages/mirai/lib/src/utils/action_type.dart | 3 +- packages/mirai/pubspec.yaml | 1 - 47 files changed, 713 insertions(+), 659 deletions(-) create mode 100644 examples/mirai_gallery/assets/json/sign_in_screen.json create mode 100644 packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data.dart create mode 100644 packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data.freezed.dart create mode 100644 packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data.g.dart create mode 100644 packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data_parser.dart rename packages/mirai/lib/src/action_parsers/{mirai_navigate_action => mirai_navigate}/mirai_navigate_action.dart (85%) rename packages/mirai/lib/src/action_parsers/{mirai_navigate_action => mirai_navigate}/mirai_navigate_action.freezed.dart (95%) rename packages/mirai/lib/src/action_parsers/{mirai_navigate_action => mirai_navigate}/mirai_navigate_action.g.dart (94%) rename packages/mirai/lib/src/action_parsers/{mirai_navigate_action => mirai_navigate}/mirai_navigate_action_parser.dart (95%) create mode 100644 packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart rename packages/mirai/lib/src/{network/mirai_request.freezed.dart => action_parsers/mirai_network_request/mirai_network_request.freezed.dart} (76%) rename packages/mirai/lib/src/{network/mirai_request.g.dart => action_parsers/mirai_network_request/mirai_network_request.g.dart} (71%) create mode 100644 packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart delete mode 100644 packages/mirai/lib/src/action_parsers/mirai_none_action/mirai_none_action_parser.dart delete mode 100644 packages/mirai/lib/src/action_parsers/mirai_request_action/mirai_request_action_parser.dart delete mode 100644 packages/mirai/lib/src/network/mirai_network.dart delete mode 100644 packages/mirai/lib/src/network/mirai_request.dart delete mode 100644 packages/mirai/lib/src/network/network.dart delete mode 100644 packages/mirai/lib/src/parsers/mirai_form/cubit/mirai_form_cubit.dart delete mode 100644 packages/mirai/lib/src/parsers/mirai_form/cubit/mirai_form_state.dart delete mode 100644 packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field.dart delete mode 100644 packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field.freezed.dart delete mode 100644 packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field.g.dart delete mode 100644 packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field_parser.dart create mode 100644 packages/mirai/lib/src/services/mirai_network_service.dart create mode 100644 packages/mirai/lib/src/services/services.dart diff --git a/examples/mirai_gallery/assets/json/example_light_theme.json b/examples/mirai_gallery/assets/json/example_light_theme.json index 5cb79b8e..48a2ca08 100644 --- a/examples/mirai_gallery/assets/json/example_light_theme.json +++ b/examples/mirai_gallery/assets/json/example_light_theme.json @@ -1,7 +1,6 @@ { "brightness": "light", "disabledColor": "#60FEF7FF", - "fontFamily": "Handjet", "colorScheme": { "brightness": "light", "primary": "#6750a4", diff --git a/examples/mirai_gallery/assets/json/sign_in_screen.json b/examples/mirai_gallery/assets/json/sign_in_screen.json new file mode 100644 index 00000000..a407e7dd --- /dev/null +++ b/examples/mirai_gallery/assets/json/sign_in_screen.json @@ -0,0 +1,120 @@ +{ + "type": "scaffold", + "resizeToAvoidBottomInset": false, + "appBar": { + "type": "appBar" + }, + "body": { + "type": "padding", + "padding": { + "top": 24, + "bottom": 40, + "left": 24, + "right": 24 + }, + "child": { + "type": "form", + "child": { + "type": "column", + "crossAxisAlignment": "start", + "children": [ + { + "type": "text", + "data": "Welcome Back!", + "style": { + "fontSize": 32, + "fontWeight": "w700" + } + }, + { + "type": "sizedBox", + "height": 40 + }, + { + "id": "email", + "type": "textFormField", + "keyboardType": "emailAddress", + "textInputAction": "next", + "maxLines": 1, + "decoration": { + "hintText": "Email Address" + } + }, + { + "type": "sizedBox", + "height": 16 + }, + { + "id": "password", + "type": "textFormField", + "keyboardType": "visiblePassword", + "textInputAction": "done", + "maxLines": 1, + "obscureText": true, + "decoration": { + "hintText": "Password", + "suffixIcon": { + "type": "icon", + "iconType": "cupertino", + "icon": "eye", + "size": 20 + } + } + }, + { + "type": "sizedBox", + "height": 8 + }, + { + "type": "row", + "mainAxisAlignment": "end", + "children": [ + { + "type": "textButton", + "onPressed": {}, + "child": { + "type": "text", + "data": "Forgot Password?", + "style": { + "fontSize": 14, + "fontWeight": "w500", + "color": "#80FFFFFF" + } + } + } + ] + }, + { + "type": "expanded", + "child": { + "type": "sizedBox", + "height": 24 + } + }, + { + "type": "elevatedButton", + "child": { + "type": "text", + "data": "Sign In 1" + }, + "onPressed": { + "actionType": "networkRequest", + "url": "https://dummyjson.com/auth/login", + "method": "post", + "headers": { + "Content-Type": "application/json" + }, + "data": { + "username": { + "actionType": "getFormDataValue", + "id": "email" + }, + "password": "0lelplR" + } + } + } + ] + } + } + } +} \ No newline at end of file diff --git a/examples/mirai_gallery/lib/app/home/home_screen.dart b/examples/mirai_gallery/lib/app/home/home_screen.dart index e337d096..73d92bd1 100644 --- a/examples/mirai_gallery/lib/app/home/home_screen.dart +++ b/examples/mirai_gallery/lib/app/home/home_screen.dart @@ -6,6 +6,6 @@ class HomeScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return Mirai.fromAssets('assets/json/home_screen.json') ?? const SizedBox(); + return Mirai.fromAssets('assets/json/sign_in_screen.json') ?? const SizedBox(); } } diff --git a/examples/mirai_gallery/lib/main.dart b/examples/mirai_gallery/lib/main.dart index 7d6046ac..1afdb79c 100644 --- a/examples/mirai_gallery/lib/main.dart +++ b/examples/mirai_gallery/lib/main.dart @@ -1,3 +1,7 @@ +import 'dart:io'; + +import 'package:dio/dio.dart'; +import 'package:dio/io.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:mirai/mirai.dart'; @@ -8,11 +12,18 @@ import 'package:mirai_gallery/app_theme/app_theme_cubit.dart'; import 'package:mirai_webview/mirai_webview.dart'; void main() async { + Dio dio = Dio(); + (dio.httpClientAdapter as IOHttpClientAdapter).createHttpClient = () => + HttpClient() + ..badCertificateCallback = + (X509Certificate cert, String host, int port) => true; + await Mirai.initialize( parsers: const [ ExampleScreenParser(), MiraiWebViewParser(), ], + dio: dio, ); runApp(const MyApp()); diff --git a/examples/mirai_gallery/pubspec.lock b/examples/mirai_gallery/pubspec.lock index f13a4d84..d79c901e 100644 --- a/examples/mirai_gallery/pubspec.lock +++ b/examples/mirai_gallery/pubspec.lock @@ -186,7 +186,7 @@ packages: source: hosted version: "2.3.2" dio: - dependency: transitive + dependency: "direct main" description: name: dio sha256: ce75a1b40947fea0a0e16ce73337122a86762e38b982e1ccb909daa3b9bc4197 diff --git a/examples/mirai_gallery/pubspec.yaml b/examples/mirai_gallery/pubspec.yaml index 3569c1f3..68cd1544 100644 --- a/examples/mirai_gallery/pubspec.yaml +++ b/examples/mirai_gallery/pubspec.yaml @@ -39,6 +39,7 @@ dependencies: flutter_bloc: ^8.1.3 mirai: ^0.5.1 mirai_webview: ^0.0.2 + dio: dev_dependencies: flutter_test: diff --git a/packages/mirai/lib/mirai.dart b/packages/mirai/lib/mirai.dart index 0849b5d7..40e2acd2 100644 --- a/packages/mirai/lib/mirai.dart +++ b/packages/mirai/lib/mirai.dart @@ -2,7 +2,6 @@ library mirai; export 'package:mirai/src/action_parsers/action_parsers.dart'; export 'package:mirai/src/framework/framework.dart'; -export 'package:mirai/src/network/network.dart'; export 'package:mirai/src/parsers/parsers.dart'; export 'package:mirai/src/utils/utils.dart'; export 'package:mirai_framework/mirai_framework.dart'; diff --git a/packages/mirai/lib/src/action_parsers/action_parsers.dart b/packages/mirai/lib/src/action_parsers/action_parsers.dart index 817f1d80..17dbd876 100644 --- a/packages/mirai/lib/src/action_parsers/action_parsers.dart +++ b/packages/mirai/lib/src/action_parsers/action_parsers.dart @@ -1,5 +1,4 @@ export 'package:mirai/src/action_parsers/mirai_dialog_action/mirai_dialog_action.dart'; +export 'package:mirai/src/action_parsers/mirai_form_data/mirai_form_data.dart'; export 'package:mirai/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action_parser.dart'; -export 'package:mirai/src/action_parsers/mirai_navigate_action/mirai_navigate_action_parser.dart'; -export 'package:mirai/src/action_parsers/mirai_none_action/mirai_none_action_parser.dart'; -export 'package:mirai/src/action_parsers/mirai_request_action/mirai_request_action_parser.dart'; +export 'package:mirai/src/action_parsers/mirai_navigate/mirai_navigate_action_parser.dart'; diff --git a/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.dart b/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.dart index 76de74dd..5b67e656 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:mirai/src/network/mirai_request.dart'; +import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; export 'mirai_dialog_action_parser.dart'; @@ -11,7 +11,7 @@ part 'mirai_dialog_action.g.dart'; class MiraiDialogAction with _$MiraiDialogAction { const factory MiraiDialogAction({ Map? widget, - MiraiRequest? request, + MiraiNetworkRequest? request, String? assetPath, @Default(true) bool barrierDismissible, String? barrierColor, diff --git a/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.freezed.dart b/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.freezed.dart index 007de1e1..9d4d42a6 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.freezed.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.freezed.dart @@ -21,7 +21,7 @@ MiraiDialogAction _$MiraiDialogActionFromJson(Map json) { /// @nodoc mixin _$MiraiDialogAction { Map? get widget => throw _privateConstructorUsedError; - MiraiRequest? get request => throw _privateConstructorUsedError; + MiraiNetworkRequest? get request => throw _privateConstructorUsedError; String? get assetPath => throw _privateConstructorUsedError; bool get barrierDismissible => throw _privateConstructorUsedError; String? get barrierColor => throw _privateConstructorUsedError; @@ -44,7 +44,7 @@ abstract class $MiraiDialogActionCopyWith<$Res> { @useResult $Res call( {Map? widget, - MiraiRequest? request, + MiraiNetworkRequest? request, String? assetPath, bool barrierDismissible, String? barrierColor, @@ -52,7 +52,7 @@ abstract class $MiraiDialogActionCopyWith<$Res> { bool useSafeArea, TraversalEdgeBehavior? traversalEdgeBehavior}); - $MiraiRequestCopyWith<$Res>? get request; + $MiraiNetworkRequestCopyWith<$Res>? get request; } /// @nodoc @@ -85,7 +85,7 @@ class _$MiraiDialogActionCopyWithImpl<$Res, $Val extends MiraiDialogAction> request: freezed == request ? _value.request : request // ignore: cast_nullable_to_non_nullable - as MiraiRequest?, + as MiraiNetworkRequest?, assetPath: freezed == assetPath ? _value.assetPath : assetPath // ignore: cast_nullable_to_non_nullable @@ -115,12 +115,12 @@ class _$MiraiDialogActionCopyWithImpl<$Res, $Val extends MiraiDialogAction> @override @pragma('vm:prefer-inline') - $MiraiRequestCopyWith<$Res>? get request { + $MiraiNetworkRequestCopyWith<$Res>? get request { if (_value.request == null) { return null; } - return $MiraiRequestCopyWith<$Res>(_value.request!, (value) { + return $MiraiNetworkRequestCopyWith<$Res>(_value.request!, (value) { return _then(_value.copyWith(request: value) as $Val); }); } @@ -136,7 +136,7 @@ abstract class _$$_MiraiDialogActionCopyWith<$Res> @useResult $Res call( {Map? widget, - MiraiRequest? request, + MiraiNetworkRequest? request, String? assetPath, bool barrierDismissible, String? barrierColor, @@ -145,7 +145,7 @@ abstract class _$$_MiraiDialogActionCopyWith<$Res> TraversalEdgeBehavior? traversalEdgeBehavior}); @override - $MiraiRequestCopyWith<$Res>? get request; + $MiraiNetworkRequestCopyWith<$Res>? get request; } /// @nodoc @@ -176,7 +176,7 @@ class __$$_MiraiDialogActionCopyWithImpl<$Res> request: freezed == request ? _value.request : request // ignore: cast_nullable_to_non_nullable - as MiraiRequest?, + as MiraiNetworkRequest?, assetPath: freezed == assetPath ? _value.assetPath : assetPath // ignore: cast_nullable_to_non_nullable @@ -233,7 +233,7 @@ class _$_MiraiDialogAction implements _MiraiDialogAction { } @override - final MiraiRequest? request; + final MiraiNetworkRequest? request; @override final String? assetPath; @override @@ -306,7 +306,7 @@ class _$_MiraiDialogAction implements _MiraiDialogAction { abstract class _MiraiDialogAction implements MiraiDialogAction { const factory _MiraiDialogAction( {final Map? widget, - final MiraiRequest? request, + final MiraiNetworkRequest? request, final String? assetPath, final bool barrierDismissible, final String? barrierColor, @@ -321,7 +321,7 @@ abstract class _MiraiDialogAction implements MiraiDialogAction { @override Map? get widget; @override - MiraiRequest? get request; + MiraiNetworkRequest? get request; @override String? get assetPath; @override diff --git a/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.g.dart b/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.g.dart index 45969cde..dd37fefc 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.g.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.g.dart @@ -11,7 +11,8 @@ _$_MiraiDialogAction _$$_MiraiDialogActionFromJson(Map json) => widget: json['widget'] as Map?, request: json['request'] == null ? null - : MiraiRequest.fromJson(json['request'] as Map), + : MiraiNetworkRequest.fromJson( + json['request'] as Map), assetPath: json['assetPath'] as String?, barrierDismissible: json['barrierDismissible'] as bool? ?? true, barrierColor: json['barrierColor'] as String?, diff --git a/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action_parser.dart index 2e2cad10..2c258b3c 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action_parser.dart @@ -35,7 +35,7 @@ class MiraiDialogActionParser extends MiraiActionParser { return _showDialog( context, model, - Mirai.fromNetwork(model.request!), + Mirai.fromNetwork(model.request!, context), ); } } diff --git a/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data.dart b/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data.dart new file mode 100644 index 00000000..2335d151 --- /dev/null +++ b/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data.dart @@ -0,0 +1,14 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'mirai_form_data.freezed.dart'; +part 'mirai_form_data.g.dart'; + +@freezed +class MiraiFormData with _$MiraiFormData { + const factory MiraiFormData({ + required String id, + }) = _MiraiFormData; + + factory MiraiFormData.fromJson(Map json) => + _$MiraiFormDataFromJson(json); +} diff --git a/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data.freezed.dart b/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data.freezed.dart new file mode 100644 index 00000000..ea0bbc75 --- /dev/null +++ b/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data.freezed.dart @@ -0,0 +1,151 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'mirai_form_data.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +MiraiFormData _$MiraiFormDataFromJson(Map json) { + return _MiraiFormData.fromJson(json); +} + +/// @nodoc +mixin _$MiraiFormData { + String get id => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $MiraiFormDataCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MiraiFormDataCopyWith<$Res> { + factory $MiraiFormDataCopyWith( + MiraiFormData value, $Res Function(MiraiFormData) then) = + _$MiraiFormDataCopyWithImpl<$Res, MiraiFormData>; + @useResult + $Res call({String id}); +} + +/// @nodoc +class _$MiraiFormDataCopyWithImpl<$Res, $Val extends MiraiFormData> + implements $MiraiFormDataCopyWith<$Res> { + _$MiraiFormDataCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$_MiraiFormDataCopyWith<$Res> + implements $MiraiFormDataCopyWith<$Res> { + factory _$$_MiraiFormDataCopyWith( + _$_MiraiFormData value, $Res Function(_$_MiraiFormData) then) = + __$$_MiraiFormDataCopyWithImpl<$Res>; + @override + @useResult + $Res call({String id}); +} + +/// @nodoc +class __$$_MiraiFormDataCopyWithImpl<$Res> + extends _$MiraiFormDataCopyWithImpl<$Res, _$_MiraiFormData> + implements _$$_MiraiFormDataCopyWith<$Res> { + __$$_MiraiFormDataCopyWithImpl( + _$_MiraiFormData _value, $Res Function(_$_MiraiFormData) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + }) { + return _then(_$_MiraiFormData( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_MiraiFormData implements _MiraiFormData { + const _$_MiraiFormData({required this.id}); + + factory _$_MiraiFormData.fromJson(Map json) => + _$$_MiraiFormDataFromJson(json); + + @override + final String id; + + @override + String toString() { + return 'MiraiFormData(id: $id)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_MiraiFormData && + (identical(other.id, id) || other.id == id)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_MiraiFormDataCopyWith<_$_MiraiFormData> get copyWith => + __$$_MiraiFormDataCopyWithImpl<_$_MiraiFormData>(this, _$identity); + + @override + Map toJson() { + return _$$_MiraiFormDataToJson( + this, + ); + } +} + +abstract class _MiraiFormData implements MiraiFormData { + const factory _MiraiFormData({required final String id}) = _$_MiraiFormData; + + factory _MiraiFormData.fromJson(Map json) = + _$_MiraiFormData.fromJson; + + @override + String get id; + @override + @JsonKey(ignore: true) + _$$_MiraiFormDataCopyWith<_$_MiraiFormData> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data.g.dart b/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data.g.dart new file mode 100644 index 00000000..7252433b --- /dev/null +++ b/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data.g.dart @@ -0,0 +1,17 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mirai_form_data.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_MiraiFormData _$$_MiraiFormDataFromJson(Map json) => + _$_MiraiFormData( + id: json['id'] as String, + ); + +Map _$$_MiraiFormDataToJson(_$_MiraiFormData instance) => + { + 'id': instance.id, + }; diff --git a/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data_parser.dart new file mode 100644 index 00000000..b815dd48 --- /dev/null +++ b/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data_parser.dart @@ -0,0 +1,23 @@ +import 'package:flutter/widgets.dart'; +import 'package:mirai/src/action_parsers/mirai_form_data/mirai_form_data.dart'; +import 'package:mirai/src/parsers/mirai_form/mirai_form_parser.dart'; +import 'package:mirai/src/utils/log.dart'; +import 'package:mirai_framework/mirai_framework.dart'; + +class MiraiFormDataActionParser extends MiraiActionParser { + const MiraiFormDataActionParser(); + + @override + String get actionType => 'getFormDataValue'; + + @override + MiraiFormData getModel(Map json) => + MiraiFormData.fromJson(json); + + @override + String onCall(BuildContext context, MiraiFormData model) { + final MiraiFormScope formScope = MiraiFormScope.of(context); + Log.d("value ${model.id}: ${formScope.formData[model.id]}"); + return formScope.formData[model.id].toString(); + } +} diff --git a/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action.dart b/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action.dart index 376e7791..e9e9d8fa 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action.dart @@ -1,5 +1,5 @@ import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:mirai/src/network/mirai_request.dart'; +import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; import 'package:mirai/src/parsers/mirai_border/mirai_border.dart'; import 'package:mirai/src/parsers/mirai_box_constraints/mirai_box_constraints.dart'; @@ -10,7 +10,7 @@ part 'mirai_modal_bottom_sheet_action.g.dart'; class MiraiModalBottomSheetAction with _$MiraiModalBottomSheetAction { const factory MiraiModalBottomSheetAction({ Map? widget, - MiraiRequest? request, + MiraiNetworkRequest? request, String? assetPath, String? backgroundColor, String? barrierLabel, diff --git a/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action.freezed.dart b/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action.freezed.dart index 596c2f49..8c9eabf1 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action.freezed.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action.freezed.dart @@ -22,7 +22,7 @@ MiraiModalBottomSheetAction _$MiraiModalBottomSheetActionFromJson( /// @nodoc mixin _$MiraiModalBottomSheetAction { Map? get widget => throw _privateConstructorUsedError; - MiraiRequest? get request => throw _privateConstructorUsedError; + MiraiNetworkRequest? get request => throw _privateConstructorUsedError; String? get assetPath => throw _privateConstructorUsedError; String? get backgroundColor => throw _privateConstructorUsedError; String? get barrierLabel => throw _privateConstructorUsedError; @@ -53,7 +53,7 @@ abstract class $MiraiModalBottomSheetActionCopyWith<$Res> { @useResult $Res call( {Map? widget, - MiraiRequest? request, + MiraiNetworkRequest? request, String? assetPath, String? backgroundColor, String? barrierLabel, @@ -68,7 +68,7 @@ abstract class $MiraiModalBottomSheetActionCopyWith<$Res> { bool? showDragHandle, bool useSafeArea}); - $MiraiRequestCopyWith<$Res>? get request; + $MiraiNetworkRequestCopyWith<$Res>? get request; $MiraiBorderCopyWith<$Res>? get shape; $MiraiBoxConstraintsCopyWith<$Res>? get constraints; } @@ -111,7 +111,7 @@ class _$MiraiModalBottomSheetActionCopyWithImpl<$Res, request: freezed == request ? _value.request : request // ignore: cast_nullable_to_non_nullable - as MiraiRequest?, + as MiraiNetworkRequest?, assetPath: freezed == assetPath ? _value.assetPath : assetPath // ignore: cast_nullable_to_non_nullable @@ -169,12 +169,12 @@ class _$MiraiModalBottomSheetActionCopyWithImpl<$Res, @override @pragma('vm:prefer-inline') - $MiraiRequestCopyWith<$Res>? get request { + $MiraiNetworkRequestCopyWith<$Res>? get request { if (_value.request == null) { return null; } - return $MiraiRequestCopyWith<$Res>(_value.request!, (value) { + return $MiraiNetworkRequestCopyWith<$Res>(_value.request!, (value) { return _then(_value.copyWith(request: value) as $Val); }); } @@ -215,7 +215,7 @@ abstract class _$$_MiraiModalBottomSheetActionCopyWith<$Res> @useResult $Res call( {Map? widget, - MiraiRequest? request, + MiraiNetworkRequest? request, String? assetPath, String? backgroundColor, String? barrierLabel, @@ -231,7 +231,7 @@ abstract class _$$_MiraiModalBottomSheetActionCopyWith<$Res> bool useSafeArea}); @override - $MiraiRequestCopyWith<$Res>? get request; + $MiraiNetworkRequestCopyWith<$Res>? get request; @override $MiraiBorderCopyWith<$Res>? get shape; @override @@ -275,7 +275,7 @@ class __$$_MiraiModalBottomSheetActionCopyWithImpl<$Res> request: freezed == request ? _value.request : request // ignore: cast_nullable_to_non_nullable - as MiraiRequest?, + as MiraiNetworkRequest?, assetPath: freezed == assetPath ? _value.assetPath : assetPath // ignore: cast_nullable_to_non_nullable @@ -367,7 +367,7 @@ class _$_MiraiModalBottomSheetAction implements _MiraiModalBottomSheetAction { } @override - final MiraiRequest? request; + final MiraiNetworkRequest? request; @override final String? assetPath; @override @@ -478,7 +478,7 @@ abstract class _MiraiModalBottomSheetAction implements MiraiModalBottomSheetAction { const factory _MiraiModalBottomSheetAction( {final Map? widget, - final MiraiRequest? request, + final MiraiNetworkRequest? request, final String? assetPath, final String? backgroundColor, final String? barrierLabel, @@ -499,7 +499,7 @@ abstract class _MiraiModalBottomSheetAction @override Map? get widget; @override - MiraiRequest? get request; + MiraiNetworkRequest? get request; @override String? get assetPath; @override diff --git a/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action.g.dart b/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action.g.dart index 6c797ab2..c45a44b9 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action.g.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action.g.dart @@ -12,7 +12,8 @@ _$_MiraiModalBottomSheetAction _$$_MiraiModalBottomSheetActionFromJson( widget: json['widget'] as Map?, request: json['request'] == null ? null - : MiraiRequest.fromJson(json['request'] as Map), + : MiraiNetworkRequest.fromJson( + json['request'] as Map), assetPath: json['assetPath'] as String?, backgroundColor: json['backgroundColor'] as String?, barrierLabel: json['barrierLabel'] as String?, diff --git a/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action_parser.dart index 84cc69af..f060a4ab 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action_parser.dart @@ -40,7 +40,7 @@ class MiraiModalBottomSheetActionParser return _showModalBottomSheet( context, model, - Mirai.fromNetwork(model.request!), + Mirai.fromNetwork(model.request!, context), ); } } diff --git a/packages/mirai/lib/src/action_parsers/mirai_navigate_action/mirai_navigate_action.dart b/packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action.dart similarity index 85% rename from packages/mirai/lib/src/action_parsers/mirai_navigate_action/mirai_navigate_action.dart rename to packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action.dart index 9298d3f1..a926430d 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_navigate_action/mirai_navigate_action.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action.dart @@ -1,5 +1,5 @@ import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:mirai/src/network/mirai_request.dart'; +import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; part 'mirai_navigate_action.freezed.dart'; part 'mirai_navigate_action.g.dart'; @@ -20,7 +20,7 @@ class MiraiNavigateAction with _$MiraiNavigateAction { const MiraiNavigateAction._(); factory MiraiNavigateAction({ - MiraiRequest? request, + MiraiNetworkRequest? request, Map? widgetJson, String? assetPath, String? routeName, diff --git a/packages/mirai/lib/src/action_parsers/mirai_navigate_action/mirai_navigate_action.freezed.dart b/packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action.freezed.dart similarity index 95% rename from packages/mirai/lib/src/action_parsers/mirai_navigate_action/mirai_navigate_action.freezed.dart rename to packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action.freezed.dart index 1f77a153..08512c91 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_navigate_action/mirai_navigate_action.freezed.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action.freezed.dart @@ -20,7 +20,7 @@ MiraiNavigateAction _$MiraiNavigateActionFromJson(Map json) { /// @nodoc mixin _$MiraiNavigateAction { - MiraiRequest? get request => throw _privateConstructorUsedError; + MiraiNetworkRequest? get request => throw _privateConstructorUsedError; Map? get widgetJson => throw _privateConstructorUsedError; String? get assetPath => throw _privateConstructorUsedError; String? get routeName => throw _privateConstructorUsedError; @@ -41,7 +41,7 @@ abstract class $MiraiNavigateActionCopyWith<$Res> { _$MiraiNavigateActionCopyWithImpl<$Res, MiraiNavigateAction>; @useResult $Res call( - {MiraiRequest? request, + {MiraiNetworkRequest? request, Map? widgetJson, String? assetPath, String? routeName, @@ -49,7 +49,7 @@ abstract class $MiraiNavigateActionCopyWith<$Res> { Map? result, Map? arguments}); - $MiraiRequestCopyWith<$Res>? get request; + $MiraiNetworkRequestCopyWith<$Res>? get request; } /// @nodoc @@ -77,7 +77,7 @@ class _$MiraiNavigateActionCopyWithImpl<$Res, $Val extends MiraiNavigateAction> request: freezed == request ? _value.request : request // ignore: cast_nullable_to_non_nullable - as MiraiRequest?, + as MiraiNetworkRequest?, widgetJson: freezed == widgetJson ? _value.widgetJson : widgetJson // ignore: cast_nullable_to_non_nullable @@ -107,12 +107,12 @@ class _$MiraiNavigateActionCopyWithImpl<$Res, $Val extends MiraiNavigateAction> @override @pragma('vm:prefer-inline') - $MiraiRequestCopyWith<$Res>? get request { + $MiraiNetworkRequestCopyWith<$Res>? get request { if (_value.request == null) { return null; } - return $MiraiRequestCopyWith<$Res>(_value.request!, (value) { + return $MiraiNetworkRequestCopyWith<$Res>(_value.request!, (value) { return _then(_value.copyWith(request: value) as $Val); }); } @@ -127,7 +127,7 @@ abstract class _$$_MiraiNavigateActionCopyWith<$Res> @override @useResult $Res call( - {MiraiRequest? request, + {MiraiNetworkRequest? request, Map? widgetJson, String? assetPath, String? routeName, @@ -136,7 +136,7 @@ abstract class _$$_MiraiNavigateActionCopyWith<$Res> Map? arguments}); @override - $MiraiRequestCopyWith<$Res>? get request; + $MiraiNetworkRequestCopyWith<$Res>? get request; } /// @nodoc @@ -162,7 +162,7 @@ class __$$_MiraiNavigateActionCopyWithImpl<$Res> request: freezed == request ? _value.request : request // ignore: cast_nullable_to_non_nullable - as MiraiRequest?, + as MiraiNetworkRequest?, widgetJson: freezed == widgetJson ? _value._widgetJson : widgetJson // ignore: cast_nullable_to_non_nullable @@ -211,7 +211,7 @@ class _$_MiraiNavigateAction extends _MiraiNavigateAction { _$$_MiraiNavigateActionFromJson(json); @override - final MiraiRequest? request; + final MiraiNetworkRequest? request; final Map? _widgetJson; @override Map? get widgetJson { @@ -301,7 +301,7 @@ class _$_MiraiNavigateAction extends _MiraiNavigateAction { abstract class _MiraiNavigateAction extends MiraiNavigateAction { factory _MiraiNavigateAction( - {final MiraiRequest? request, + {final MiraiNetworkRequest? request, final Map? widgetJson, final String? assetPath, final String? routeName, @@ -314,7 +314,7 @@ abstract class _MiraiNavigateAction extends MiraiNavigateAction { _$_MiraiNavigateAction.fromJson; @override - MiraiRequest? get request; + MiraiNetworkRequest? get request; @override Map? get widgetJson; @override diff --git a/packages/mirai/lib/src/action_parsers/mirai_navigate_action/mirai_navigate_action.g.dart b/packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action.g.dart similarity index 94% rename from packages/mirai/lib/src/action_parsers/mirai_navigate_action/mirai_navigate_action.g.dart rename to packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action.g.dart index cc320d18..f313d29d 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_navigate_action/mirai_navigate_action.g.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action.g.dart @@ -11,7 +11,8 @@ _$_MiraiNavigateAction _$$_MiraiNavigateActionFromJson( _$_MiraiNavigateAction( request: json['request'] == null ? null - : MiraiRequest.fromJson(json['request'] as Map), + : MiraiNetworkRequest.fromJson( + json['request'] as Map), widgetJson: json['widgetJson'] as Map?, assetPath: json['assetPath'] as String?, routeName: json['routeName'] as String?, diff --git a/packages/mirai/lib/src/action_parsers/mirai_navigate_action/mirai_navigate_action_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action_parser.dart similarity index 95% rename from packages/mirai/lib/src/action_parsers/mirai_navigate_action/mirai_navigate_action_parser.dart rename to packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action_parser.dart index 0bea07e6..6bfd96e3 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_navigate_action/mirai_navigate_action_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action_parser.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:mirai/src/action_parsers/mirai_navigate_action/mirai_navigate_action.dart'; +import 'package:mirai/src/action_parsers/mirai_navigate/mirai_navigate_action.dart'; import 'package:mirai/src/framework/framework.dart'; import 'package:mirai/src/utils/action_type.dart'; import 'package:mirai_framework/mirai_framework.dart'; @@ -22,7 +22,7 @@ class MiraiNavigateActionParser extends MiraiActionParser { if (model.widgetJson != null) { widget = Mirai.fromJson(model.widgetJson, context); } else if (model.request != null) { - widget = Mirai.fromNetwork(model.request!); + widget = Mirai.fromNetwork(model.request!, context); } else if (model.assetPath != null) { widget = Mirai.fromAssets(model.assetPath!); } diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart new file mode 100644 index 00000000..7455e292 --- /dev/null +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart @@ -0,0 +1,26 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'mirai_network_request.freezed.dart'; +part 'mirai_network_request.g.dart'; + +enum Method { + get, + post, + put, + delete, +} + +@freezed +class MiraiNetworkRequest with _$MiraiNetworkRequest { + const factory MiraiNetworkRequest({ + required String url, + @Default(Method.get) Method method, + Map? queryParameters, + Map? headers, + String? contentType, + Map? data, + }) = _MiraiNetworkRequest; + + factory MiraiNetworkRequest.fromJson(Map json) => + _$MiraiNetworkRequestFromJson(json); +} diff --git a/packages/mirai/lib/src/network/mirai_request.freezed.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart similarity index 76% rename from packages/mirai/lib/src/network/mirai_request.freezed.dart rename to packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart index 647eba0f..78f9a5ea 100644 --- a/packages/mirai/lib/src/network/mirai_request.freezed.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart @@ -3,7 +3,7 @@ // ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark -part of 'mirai_request.dart'; +part of 'mirai_network_request.dart'; // ************************************************************************** // FreezedGenerator @@ -14,12 +14,12 @@ T _$identity(T value) => value; final _privateConstructorUsedError = UnsupportedError( 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); -MiraiRequest _$MiraiRequestFromJson(Map json) { - return _MiraiRequest.fromJson(json); +MiraiNetworkRequest _$MiraiNetworkRequestFromJson(Map json) { + return _MiraiNetworkRequest.fromJson(json); } /// @nodoc -mixin _$MiraiRequest { +mixin _$MiraiNetworkRequest { String get url => throw _privateConstructorUsedError; Method get method => throw _privateConstructorUsedError; Map? get queryParameters => @@ -30,15 +30,15 @@ mixin _$MiraiRequest { Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) - $MiraiRequestCopyWith get copyWith => + $MiraiNetworkRequestCopyWith get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class $MiraiRequestCopyWith<$Res> { - factory $MiraiRequestCopyWith( - MiraiRequest value, $Res Function(MiraiRequest) then) = - _$MiraiRequestCopyWithImpl<$Res, MiraiRequest>; +abstract class $MiraiNetworkRequestCopyWith<$Res> { + factory $MiraiNetworkRequestCopyWith( + MiraiNetworkRequest value, $Res Function(MiraiNetworkRequest) then) = + _$MiraiNetworkRequestCopyWithImpl<$Res, MiraiNetworkRequest>; @useResult $Res call( {String url, @@ -50,9 +50,9 @@ abstract class $MiraiRequestCopyWith<$Res> { } /// @nodoc -class _$MiraiRequestCopyWithImpl<$Res, $Val extends MiraiRequest> - implements $MiraiRequestCopyWith<$Res> { - _$MiraiRequestCopyWithImpl(this._value, this._then); +class _$MiraiNetworkRequestCopyWithImpl<$Res, $Val extends MiraiNetworkRequest> + implements $MiraiNetworkRequestCopyWith<$Res> { + _$MiraiNetworkRequestCopyWithImpl(this._value, this._then); // ignore: unused_field final $Val _value; @@ -99,11 +99,11 @@ class _$MiraiRequestCopyWithImpl<$Res, $Val extends MiraiRequest> } /// @nodoc -abstract class _$$_MiraiRequestCopyWith<$Res> - implements $MiraiRequestCopyWith<$Res> { - factory _$$_MiraiRequestCopyWith( - _$_MiraiRequest value, $Res Function(_$_MiraiRequest) then) = - __$$_MiraiRequestCopyWithImpl<$Res>; +abstract class _$$_MiraiNetworkRequestCopyWith<$Res> + implements $MiraiNetworkRequestCopyWith<$Res> { + factory _$$_MiraiNetworkRequestCopyWith(_$_MiraiNetworkRequest value, + $Res Function(_$_MiraiNetworkRequest) then) = + __$$_MiraiNetworkRequestCopyWithImpl<$Res>; @override @useResult $Res call( @@ -116,11 +116,11 @@ abstract class _$$_MiraiRequestCopyWith<$Res> } /// @nodoc -class __$$_MiraiRequestCopyWithImpl<$Res> - extends _$MiraiRequestCopyWithImpl<$Res, _$_MiraiRequest> - implements _$$_MiraiRequestCopyWith<$Res> { - __$$_MiraiRequestCopyWithImpl( - _$_MiraiRequest _value, $Res Function(_$_MiraiRequest) _then) +class __$$_MiraiNetworkRequestCopyWithImpl<$Res> + extends _$MiraiNetworkRequestCopyWithImpl<$Res, _$_MiraiNetworkRequest> + implements _$$_MiraiNetworkRequestCopyWith<$Res> { + __$$_MiraiNetworkRequestCopyWithImpl(_$_MiraiNetworkRequest _value, + $Res Function(_$_MiraiNetworkRequest) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -133,7 +133,7 @@ class __$$_MiraiRequestCopyWithImpl<$Res> Object? contentType = freezed, Object? data = freezed, }) { - return _then(_$_MiraiRequest( + return _then(_$_MiraiNetworkRequest( url: null == url ? _value.url : url // ignore: cast_nullable_to_non_nullable @@ -164,10 +164,10 @@ class __$$_MiraiRequestCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$_MiraiRequest implements _MiraiRequest { - const _$_MiraiRequest( +class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { + const _$_MiraiNetworkRequest( {required this.url, - required this.method, + this.method = Method.get, final Map? queryParameters, final Map? headers, this.contentType, @@ -176,12 +176,13 @@ class _$_MiraiRequest implements _MiraiRequest { _headers = headers, _data = data; - factory _$_MiraiRequest.fromJson(Map json) => - _$$_MiraiRequestFromJson(json); + factory _$_MiraiNetworkRequest.fromJson(Map json) => + _$$_MiraiNetworkRequestFromJson(json); @override final String url; @override + @JsonKey() final Method method; final Map? _queryParameters; @override @@ -217,14 +218,14 @@ class _$_MiraiRequest implements _MiraiRequest { @override String toString() { - return 'MiraiRequest(url: $url, method: $method, queryParameters: $queryParameters, headers: $headers, contentType: $contentType, data: $data)'; + return 'MiraiNetworkRequest(url: $url, method: $method, queryParameters: $queryParameters, headers: $headers, contentType: $contentType, data: $data)'; } @override bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$_MiraiRequest && + other is _$_MiraiNetworkRequest && (identical(other.url, url) || other.url == url) && (identical(other.method, method) || other.method == method) && const DeepCollectionEquality() @@ -249,28 +250,29 @@ class _$_MiraiRequest implements _MiraiRequest { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$_MiraiRequestCopyWith<_$_MiraiRequest> get copyWith => - __$$_MiraiRequestCopyWithImpl<_$_MiraiRequest>(this, _$identity); + _$$_MiraiNetworkRequestCopyWith<_$_MiraiNetworkRequest> get copyWith => + __$$_MiraiNetworkRequestCopyWithImpl<_$_MiraiNetworkRequest>( + this, _$identity); @override Map toJson() { - return _$$_MiraiRequestToJson( + return _$$_MiraiNetworkRequestToJson( this, ); } } -abstract class _MiraiRequest implements MiraiRequest { - const factory _MiraiRequest( +abstract class _MiraiNetworkRequest implements MiraiNetworkRequest { + const factory _MiraiNetworkRequest( {required final String url, - required final Method method, + final Method method, final Map? queryParameters, final Map? headers, final String? contentType, - final Map? data}) = _$_MiraiRequest; + final Map? data}) = _$_MiraiNetworkRequest; - factory _MiraiRequest.fromJson(Map json) = - _$_MiraiRequest.fromJson; + factory _MiraiNetworkRequest.fromJson(Map json) = + _$_MiraiNetworkRequest.fromJson; @override String get url; @@ -286,6 +288,6 @@ abstract class _MiraiRequest implements MiraiRequest { Map? get data; @override @JsonKey(ignore: true) - _$$_MiraiRequestCopyWith<_$_MiraiRequest> get copyWith => + _$$_MiraiNetworkRequestCopyWith<_$_MiraiNetworkRequest> get copyWith => throw _privateConstructorUsedError; } diff --git a/packages/mirai/lib/src/network/mirai_request.g.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart similarity index 71% rename from packages/mirai/lib/src/network/mirai_request.g.dart rename to packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart index 631cb1b1..7c2d5e72 100644 --- a/packages/mirai/lib/src/network/mirai_request.g.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart @@ -1,22 +1,25 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'mirai_request.dart'; +part of 'mirai_network_request.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** -_$_MiraiRequest _$$_MiraiRequestFromJson(Map json) => - _$_MiraiRequest( +_$_MiraiNetworkRequest _$$_MiraiNetworkRequestFromJson( + Map json) => + _$_MiraiNetworkRequest( url: json['url'] as String, - method: $enumDecode(_$MethodEnumMap, json['method']), + method: + $enumDecodeNullable(_$MethodEnumMap, json['method']) ?? Method.get, queryParameters: json['queryParameters'] as Map?, headers: json['headers'] as Map?, contentType: json['contentType'] as String?, data: json['data'] as Map?, ); -Map _$$_MiraiRequestToJson(_$_MiraiRequest instance) => +Map _$$_MiraiNetworkRequestToJson( + _$_MiraiNetworkRequest instance) => { 'url': instance.url, 'method': _$MethodEnumMap[instance.method]!, diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart new file mode 100644 index 00000000..b86dba1f --- /dev/null +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart @@ -0,0 +1,27 @@ +import 'dart:async'; + +import 'package:flutter/widgets.dart'; +import 'package:mirai/mirai.dart'; +import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; +import 'package:mirai/src/services/mirai_network_service.dart'; +import 'package:mirai/src/utils/action_type.dart'; +import 'package:mirai/src/utils/log.dart'; + +class MiraiNetworkRequestParser extends MiraiActionParser { + const MiraiNetworkRequestParser(); + + @override + String get actionType => ActionType.networkRequest.name; + + @override + MiraiNetworkRequest getModel(Map json) => + MiraiNetworkRequest.fromJson(json); + + @override + FutureOr onCall(BuildContext context, MiraiNetworkRequest model) async { + Log.d(model); + final result = await MiraiNetworkService.request(model, context); + Log.d(result); + return result; + } +} diff --git a/packages/mirai/lib/src/action_parsers/mirai_none_action/mirai_none_action_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_none_action/mirai_none_action_parser.dart deleted file mode 100644 index 6b56c922..00000000 --- a/packages/mirai/lib/src/action_parsers/mirai_none_action/mirai_none_action_parser.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'dart:async'; - -import 'package:flutter/widgets.dart'; -import 'package:mirai/src/utils/action_type.dart'; -import 'package:mirai_framework/mirai_framework.dart'; - -class MiraiNoneActionParser extends MiraiActionParser { - const MiraiNoneActionParser(); - - @override - String get actionType => ActionType.none.name; - - @override - getModel(Map json) => json; - - @override - FutureOr onCall(BuildContext context, model) {} -} diff --git a/packages/mirai/lib/src/action_parsers/mirai_request_action/mirai_request_action_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_request_action/mirai_request_action_parser.dart deleted file mode 100644 index 2de685a2..00000000 --- a/packages/mirai/lib/src/action_parsers/mirai_request_action/mirai_request_action_parser.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'dart:async'; - -import 'package:flutter/widgets.dart'; -import 'package:mirai/src/network/mirai_network.dart'; -import 'package:mirai/src/network/mirai_request.dart'; -import 'package:mirai/src/utils/action_type.dart'; -import 'package:mirai_framework/mirai_framework.dart'; - -class MiraiRequestActionParser extends MiraiActionParser { - const MiraiRequestActionParser(); - - @override - String get actionType => ActionType.request.name; - - @override - getModel(Map json) => MiraiRequest.fromJson(json); - - @override - FutureOr onCall(BuildContext context, MiraiRequest model) { - return MiraiNetwork.request(model); - } -} diff --git a/packages/mirai/lib/src/framework/mirai.dart b/packages/mirai/lib/src/framework/mirai.dart index 01d7f544..bde6cec9 100644 --- a/packages/mirai/lib/src/framework/mirai.dart +++ b/packages/mirai/lib/src/framework/mirai.dart @@ -5,16 +5,17 @@ import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:mirai/src/action_parsers/action_parsers.dart'; +import 'package:mirai/src/action_parsers/mirai_form_data/mirai_form_data_parser.dart'; +import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; +import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart'; import 'package:mirai/src/framework/mirai_registry.dart'; -import 'package:mirai/src/network/mirai_network.dart'; -import 'package:mirai/src/network/mirai_request.dart'; import 'package:mirai/src/parsers/mirai_center/mirai_center_parser.dart'; import 'package:mirai/src/parsers/mirai_check_box_widget/mirai_check_box_widget_parser.dart'; import 'package:mirai/src/parsers/mirai_form/mirai_form_parser.dart'; -import 'package:mirai/src/parsers/mirai_form_field/mirai_form_field_parser.dart'; import 'package:mirai/src/parsers/mirai_fractionally_sized_box/mirai_fractionally_sized_box_parser.dart'; import 'package:mirai/src/parsers/mirai_tab/mirai_tab_parser.dart'; import 'package:mirai/src/parsers/parsers.dart'; +import 'package:mirai/src/services/mirai_network_service.dart'; import 'package:mirai/src/utils/log.dart'; import 'package:mirai_framework/mirai_framework.dart'; @@ -59,7 +60,6 @@ class Mirai { const MiraiAlertDialogParser(), const MiraiTabParser(), const MiraiFormParser(), - const MiraiFormFieldParser(), const MiraiCheckBoxWidgetParser(), const MiraiExpandedParser(), const MiraiFlexibleParser(), @@ -67,11 +67,11 @@ class Mirai { ]; static final _actionParsers = [ - const MiraiNoneActionParser(), const MiraiNavigateActionParser(), - const MiraiRequestActionParser(), + const MiraiNetworkRequestParser(), const MiraiModalBottomSheetActionParser(), const MiraiDialogActionParser(), + const MiraiFormDataActionParser(), ]; static Future initialize({ @@ -83,7 +83,7 @@ class Mirai { _actionParsers.addAll(actionParsers); MiraiRegistry.instance.registerAll(_parsers); MiraiRegistry.instance.registerAllActions(_actionParsers); - MiraiNetwork.initialize(dio ?? Dio()); + MiraiNetworkService.initialize(dio ?? Dio()); } static Widget? fromJson(Map? json, BuildContext context) { @@ -127,12 +127,13 @@ class Mirai { } static Widget fromNetwork( - MiraiRequest request, { + MiraiNetworkRequest request, + BuildContext context, { LoadingWidgetBuilder? loadingWidget, ErrorWidgetBuilder? errorWidget, }) { return FutureBuilder( - future: MiraiNetwork.request(request), + future: MiraiNetworkService.request(request, context), builder: (context, snapshot) { switch (snapshot.connectionState) { case ConnectionState.waiting: diff --git a/packages/mirai/lib/src/network/mirai_network.dart b/packages/mirai/lib/src/network/mirai_network.dart deleted file mode 100644 index d1984421..00000000 --- a/packages/mirai/lib/src/network/mirai_network.dart +++ /dev/null @@ -1,71 +0,0 @@ -import 'package:dio/dio.dart'; -import 'package:mirai/src/network/mirai_request.dart'; - -class MiraiNetwork { - const MiraiNetwork._(); - - static late Dio _dio; - - static void initialize(Dio dio) => _dio = dio; - - static Future request(MiraiRequest request) { - switch (request.method) { - case Method.get: - return getRequest(request); - case Method.post: - return postRequest(request); - case Method.put: - return putRequest(request); - case Method.delete: - return deleteRequest(request); - } - } - - static Future getRequest(MiraiRequest request) { - return _dio.get( - request.url, - data: request.data, - queryParameters: request.queryParameters, - options: Options( - contentType: request.contentType, - headers: request.headers, - ), - ); - } - - static Future postRequest(MiraiRequest request) { - return _dio.post( - request.url, - data: request.data, - queryParameters: request.queryParameters, - options: Options( - contentType: request.contentType, - headers: request.headers, - ), - ); - } - - static Future putRequest(MiraiRequest request) async { - return _dio.put( - request.url, - data: request.data, - queryParameters: request.queryParameters, - options: Options( - contentType: request.contentType, - headers: request.headers, - ), - ); - } - - static Future deleteRequest(MiraiRequest request) async { - return _dio.delete( - request.url, - data: request.data, - queryParameters: request.queryParameters, - options: Options( - contentType: request.contentType, - headers: request.headers, - ), - ); - } -} diff --git a/packages/mirai/lib/src/network/mirai_request.dart b/packages/mirai/lib/src/network/mirai_request.dart deleted file mode 100644 index c9f01474..00000000 --- a/packages/mirai/lib/src/network/mirai_request.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'mirai_request.freezed.dart'; -part 'mirai_request.g.dart'; - -@freezed -class MiraiRequest with _$MiraiRequest { - const factory MiraiRequest({ - required String url, - required Method method, - Map? queryParameters, - Map? headers, - String? contentType, - Map? data, - }) = _MiraiRequest; - - factory MiraiRequest.fromJson(Map json) => - _$MiraiRequestFromJson(json); -} - -enum Method { - get, - post, - put, - delete, -} diff --git a/packages/mirai/lib/src/network/network.dart b/packages/mirai/lib/src/network/network.dart deleted file mode 100644 index 51f86b70..00000000 --- a/packages/mirai/lib/src/network/network.dart +++ /dev/null @@ -1,4 +0,0 @@ -library network; - -export 'mirai_network.dart'; -export 'mirai_request.dart'; diff --git a/packages/mirai/lib/src/parsers/mirai_check_box_widget/mirai_check_box_widget_parser.dart b/packages/mirai/lib/src/parsers/mirai_check_box_widget/mirai_check_box_widget_parser.dart index a170d174..dbd44a14 100644 --- a/packages/mirai/lib/src/parsers/mirai_check_box_widget/mirai_check_box_widget_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_check_box_widget/mirai_check_box_widget_parser.dart @@ -1,7 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:mirai/src/parsers/mirai_check_box_widget/mirai_check_box_widget.dart'; -import 'package:mirai/src/parsers/mirai_form/cubit/mirai_form_cubit.dart'; import 'package:mirai/src/parsers/mirai_material_color/mirai_material_color.dart'; import 'package:mirai/src/utils/color_utils.dart'; import 'package:mirai/src/utils/widget_type.dart'; @@ -40,9 +38,9 @@ class __MiraiCheckBoxWidgetState extends State<_MiraiCheckBoxWidget> { @override void initState() { if (widget.model.id != null) { - context - .read() - .registerValue(widget.model.id!, widget.model.value); + // context + // .read() + // .registerValue(widget.model.id!, widget.model.value); } super.initState(); @@ -57,12 +55,12 @@ class __MiraiCheckBoxWidgetState extends State<_MiraiCheckBoxWidget> { isMarkChecked = !isMarkChecked; }); if (widget.model.id != null) { - context - .read() - .updateValue(widget.model.id!, isMarkChecked); - context - .read() - .updateValidation(widget.model.id!, isMarkChecked); + // context + // .read() + // .updateValue(widget.model.id!, isMarkChecked); + // context + // .read() + // .updateValidation(widget.model.id!, isMarkChecked); } }, activeColor: widget.model.activeColor.toColor, diff --git a/packages/mirai/lib/src/parsers/mirai_form/cubit/mirai_form_cubit.dart b/packages/mirai/lib/src/parsers/mirai_form/cubit/mirai_form_cubit.dart deleted file mode 100644 index c91caaab..00000000 --- a/packages/mirai/lib/src/parsers/mirai_form/cubit/mirai_form_cubit.dart +++ /dev/null @@ -1,99 +0,0 @@ -import 'package:flutter_bloc/flutter_bloc.dart'; - -part 'mirai_form_state.dart'; - -class MiraiFormCubit extends Cubit { - MiraiFormCubit() : super(const MiraiFormState()); - - void validateFrom() { - final values = state.values.entries.toList(); - for (var i = 0; i < values.length; i++) { - final data = values[i].value.data; - final isValidated = values[i].value.validated; - - if (data == null || - (data is String && data.isEmpty) || - (data is bool && data == false) || - !isValidated) { - emit( - state.copyWith(formState: MiraiFromStateType.unvalidated), - ); - return; - } - } - - emit( - state.copyWith(formState: MiraiFromStateType.validated), - ); - } - - void registerValue(String key, dynamic value) { - Map? values = - Map.from(state.values); - - values.addAll({key: FormFieldModel(data: value, validated: false)}); - - emit( - MiraiFormState( - values: values, - ), - ); - - validateFrom(); - } - - bool? getValidation(String key) { - return state.values[key]?.validated; - } - - String? getValue(String key) { - return state.values[key]?.data; - } - - void updateValue(String key, dynamic value) { - Map? values = - Map.from(state.values); - - values[key] = values[key]?.copyWith(data: value) ?? FormFieldModel(); - - emit( - state.copyWith(values: values), - ); - - validateFrom(); - } - - void updateValidation(String key, bool value) { - Map values = - Map.from(state.values); - - values[key] = values[key]?.copyWith(validated: value) ?? FormFieldModel(); - - emit( - state.copyWith(values: values), - ); - - validateFrom(); - } - - void removeValue(String key) { - Map values = - Map.from(state.values); - - values.remove(key); - - emit( - state.copyWith(values: values), - ); - - validateFrom(); - } - - void removeAll() { - emit( - state.copyWith(values: {}), - ); - - validateFrom(); - } -} diff --git a/packages/mirai/lib/src/parsers/mirai_form/cubit/mirai_form_state.dart b/packages/mirai/lib/src/parsers/mirai_form/cubit/mirai_form_state.dart deleted file mode 100644 index 90fe7cd4..00000000 --- a/packages/mirai/lib/src/parsers/mirai_form/cubit/mirai_form_state.dart +++ /dev/null @@ -1,41 +0,0 @@ -part of 'mirai_form_cubit.dart'; - -enum MiraiFromStateType { unvalidated, validated, loading, submitted } - -class MiraiFormState { - const MiraiFormState({ - this.values = const {}, - this.formState = MiraiFromStateType.unvalidated, - }); - - final Map values; - final MiraiFromStateType formState; - - MiraiFormState copyWith({ - Map? values, - MiraiFromStateType? formState, - }) => - MiraiFormState( - values: values ?? this.values, - formState: formState ?? this.formState, - ); -} - -class FormFieldModel { - FormFieldModel({ - this.data, - this.validated = false, - }); - - final dynamic data; - final bool validated; - - FormFieldModel copyWith({ - dynamic data, - bool? validated, - }) => - FormFieldModel( - data: data ?? this.data, - validated: validated ?? this.validated, - ); -} diff --git a/packages/mirai/lib/src/parsers/mirai_form/mirai_form_parser.dart b/packages/mirai/lib/src/parsers/mirai_form/mirai_form_parser.dart index 1e37b497..448242ef 100644 --- a/packages/mirai/lib/src/parsers/mirai_form/mirai_form_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_form/mirai_form_parser.dart @@ -1,8 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:mirai/src/framework/framework.dart'; -import 'package:mirai/src/parsers/mirai_form/cubit/mirai_form_cubit.dart'; import 'package:mirai/src/parsers/mirai_form/mirai_form.dart'; +import 'package:mirai/src/utils/log.dart'; import 'package:mirai/src/utils/widget_type.dart'; import 'package:mirai_framework/mirai_framework.dart'; @@ -17,15 +16,73 @@ class MiraiFormParser extends MiraiParser { @override Widget parse(BuildContext context, MiraiForm model) { - return BlocProvider( - create: (_) => MiraiFormCubit(), - child: Form( - autovalidateMode: model.autovalidateMode, - child: BlocBuilder( - builder: (context, state) { - return Mirai.fromJson(model.child, context) ?? const SizedBox(); - }, - )), + return FormBuilder( + model: model, ); } } + +class FormBuilder extends StatefulWidget { + const FormBuilder({ + super.key, + required this.model, + }); + + final MiraiForm model; + + @override + State createState() => _FormBuilderState(); +} + +class _FormBuilderState extends State { + final Map _formData = {"key": "val"}; + final _formKey = GlobalKey(); + + Map getFormData() => _formData; + + void setFormData({required String key, required value}) { + _formData[key] = value; + } + + @override + Widget build(BuildContext context) { + return MiraiFormScope( + formData: _formData, + child: Builder(builder: (context) { + return Form( + key: _formKey, + onChanged: () { + Log.d("onChanged: ${MiraiFormScope.of(context).formData}"); + }, + child: + Mirai.fromJson(widget.model.child, context) ?? const SizedBox(), + ); + }), + ); + } +} + +class MiraiFormScope extends InheritedWidget { + const MiraiFormScope({ + super.key, + required super.child, + required this.formData, + }); + + final Map formData; + + static MiraiFormScope of(BuildContext context) { + final MiraiFormScope? result = + context.dependOnInheritedWidgetOfExactType(); + + if (result != null) { + return result; + } else { + throw FlutterError( + 'MiraiFormScope.of() called with a context that does not contain a MiraiFormScope.'); + } + } + + @override + bool updateShouldNotify(MiraiFormScope oldWidget) => false; +} diff --git a/packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field.dart b/packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field.dart deleted file mode 100644 index 5d04cbca..00000000 --- a/packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'mirai_form_field.freezed.dart'; -part 'mirai_form_field.g.dart'; - -@freezed -class MiraiFormField with _$MiraiFormField { - const factory MiraiFormField({ - Map? child, - }) = _MiraiFormField; - - factory MiraiFormField.fromJson(Map json) => - _$MiraiFormFieldFromJson(json); -} diff --git a/packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field.freezed.dart b/packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field.freezed.dart deleted file mode 100644 index 95e99ead..00000000 --- a/packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field.freezed.dart +++ /dev/null @@ -1,160 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'mirai_form_field.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); - -MiraiFormField _$MiraiFormFieldFromJson(Map json) { - return _MiraiFormField.fromJson(json); -} - -/// @nodoc -mixin _$MiraiFormField { - Map? get child => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $MiraiFormFieldCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $MiraiFormFieldCopyWith<$Res> { - factory $MiraiFormFieldCopyWith( - MiraiFormField value, $Res Function(MiraiFormField) then) = - _$MiraiFormFieldCopyWithImpl<$Res, MiraiFormField>; - @useResult - $Res call({Map? child}); -} - -/// @nodoc -class _$MiraiFormFieldCopyWithImpl<$Res, $Val extends MiraiFormField> - implements $MiraiFormFieldCopyWith<$Res> { - _$MiraiFormFieldCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? child = freezed, - }) { - return _then(_value.copyWith( - child: freezed == child - ? _value.child - : child // ignore: cast_nullable_to_non_nullable - as Map?, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$_MiraiFormFieldCopyWith<$Res> - implements $MiraiFormFieldCopyWith<$Res> { - factory _$$_MiraiFormFieldCopyWith( - _$_MiraiFormField value, $Res Function(_$_MiraiFormField) then) = - __$$_MiraiFormFieldCopyWithImpl<$Res>; - @override - @useResult - $Res call({Map? child}); -} - -/// @nodoc -class __$$_MiraiFormFieldCopyWithImpl<$Res> - extends _$MiraiFormFieldCopyWithImpl<$Res, _$_MiraiFormField> - implements _$$_MiraiFormFieldCopyWith<$Res> { - __$$_MiraiFormFieldCopyWithImpl( - _$_MiraiFormField _value, $Res Function(_$_MiraiFormField) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? child = freezed, - }) { - return _then(_$_MiraiFormField( - child: freezed == child - ? _value._child - : child // ignore: cast_nullable_to_non_nullable - as Map?, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$_MiraiFormField implements _MiraiFormField { - const _$_MiraiFormField({final Map? child}) : _child = child; - - factory _$_MiraiFormField.fromJson(Map json) => - _$$_MiraiFormFieldFromJson(json); - - final Map? _child; - @override - Map? get child { - final value = _child; - if (value == null) return null; - if (_child is EqualUnmodifiableMapView) return _child; - // ignore: implicit_dynamic_type - return EqualUnmodifiableMapView(value); - } - - @override - String toString() { - return 'MiraiFormField(child: $child)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$_MiraiFormField && - const DeepCollectionEquality().equals(other._child, _child)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => - Object.hash(runtimeType, const DeepCollectionEquality().hash(_child)); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$_MiraiFormFieldCopyWith<_$_MiraiFormField> get copyWith => - __$$_MiraiFormFieldCopyWithImpl<_$_MiraiFormField>(this, _$identity); - - @override - Map toJson() { - return _$$_MiraiFormFieldToJson( - this, - ); - } -} - -abstract class _MiraiFormField implements MiraiFormField { - const factory _MiraiFormField({final Map? child}) = - _$_MiraiFormField; - - factory _MiraiFormField.fromJson(Map json) = - _$_MiraiFormField.fromJson; - - @override - Map? get child; - @override - @JsonKey(ignore: true) - _$$_MiraiFormFieldCopyWith<_$_MiraiFormField> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field.g.dart b/packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field.g.dart deleted file mode 100644 index 233c9daa..00000000 --- a/packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field.g.dart +++ /dev/null @@ -1,17 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'mirai_form_field.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -_$_MiraiFormField _$$_MiraiFormFieldFromJson(Map json) => - _$_MiraiFormField( - child: json['child'] as Map?, - ); - -Map _$$_MiraiFormFieldToJson(_$_MiraiFormField instance) => - { - 'child': instance.child, - }; diff --git a/packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field_parser.dart b/packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field_parser.dart deleted file mode 100644 index 22354fac..00000000 --- a/packages/mirai/lib/src/parsers/mirai_form_field/mirai_form_field_parser.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:mirai/src/framework/framework.dart'; -import 'package:mirai/src/parsers/mirai_form/cubit/mirai_form_cubit.dart'; -import 'package:mirai/src/parsers/mirai_form_field/mirai_form_field.dart'; -import 'package:mirai/src/utils/log.dart'; -import 'package:mirai/src/utils/widget_type.dart'; -import 'package:mirai_framework/mirai_framework.dart'; - -class MiraiFormFieldParser extends MiraiParser { - const MiraiFormFieldParser(); - - @override - MiraiFormField getModel(Map json) => - MiraiFormField.fromJson(json); - - @override - String get type => WidgetType.formField.name; - - @override - Widget parse(BuildContext context, MiraiFormField model) { - Map child = Map.from(model.child ?? {}); - - try { - final formState = context.read().state.formState; - if (formState == MiraiFromStateType.unvalidated) { - child['onPressed'] = null; - } - } catch (e) { - Log.d(e); - } - - return Mirai.fromJson(child, context) ?? const SizedBox(); - } -} diff --git a/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart b/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart index 5f274eba..7f03bd5f 100644 --- a/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart @@ -1,8 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:mirai/src/framework/framework.dart'; import 'package:mirai/src/parsers/mirai_edge_insets/mirai_edge_insets.dart'; -import 'package:mirai/src/parsers/mirai_form/cubit/mirai_form_cubit.dart'; +import 'package:mirai/src/parsers/mirai_form/mirai_form_parser.dart'; import 'package:mirai/src/parsers/mirai_form_field_validator/mirai_form_validator.dart'; import 'package:mirai/src/parsers/mirai_input_decoration/mirai_input_decoration.dart'; import 'package:mirai/src/parsers/mirai_input_formatters/mirai_input_formatter.dart'; @@ -39,10 +38,10 @@ class _TextFormFieldWidget extends StatefulWidget { final MiraiTextFormField model; @override - State<_TextFormFieldWidget> createState() => __TextFormFieldWidgetState(); + State<_TextFormFieldWidget> createState() => _TextFormFieldWidgetState(); } -class __TextFormFieldWidgetState extends State<_TextFormFieldWidget> { +class _TextFormFieldWidgetState extends State<_TextFormFieldWidget> { TextEditingController controller = TextEditingController(); FocusNode? focusNode = FocusNode(); bool obscureText = false; @@ -50,9 +49,9 @@ class __TextFormFieldWidgetState extends State<_TextFormFieldWidget> { @override void initState() { if (widget.model.id != null) { - context - .read() - .registerValue(widget.model.id!, widget.model.initialValue ?? ""); + // context + // .read() + // .registerValue(widget.model.id!, widget.model.initialValue ?? ""); } controller = TextEditingController(text: widget.model.initialValue); @@ -62,15 +61,19 @@ class __TextFormFieldWidgetState extends State<_TextFormFieldWidget> { @override Widget build(BuildContext context) { + final formScope = MiraiFormScope.of(context); return TextFormField( controller: controller, focusNode: focusNode, onChanged: (value) { + Log.d("id: ${widget.model.id}"); if (widget.model.id != null) { - context.read().updateValue( - widget.model.id!, - value, - ); + formScope.formData[widget.model.id!] = value; + Log.d(formScope.formData); + // context.read().updateValue( + // widget.model.id!, + // value, + // ); } }, initialValue: widget.model.initialValue, @@ -116,9 +119,9 @@ class __TextFormFieldWidgetState extends State<_TextFormFieldWidget> { ); if (widget.model.id != null) { - context - .read() - .updateValidation(widget.model.id!, validation == null); + // context + // .read() + // .updateValidation(widget.model.id!, validation == null); } return validation; @@ -155,9 +158,9 @@ class __TextFormFieldWidgetState extends State<_TextFormFieldWidget> { String? compareVal; if (widget.model.compareId != null) { try { - compareVal = context - .read() - .getValue(widget.model.compareId!); + // compareVal = context + // .read() + // .getValue(widget.model.compareId!); } catch (e) { Log.e(e); } diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart new file mode 100644 index 00000000..6a308b7f --- /dev/null +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -0,0 +1,106 @@ +import 'package:dio/dio.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; +import 'package:mirai/src/framework/framework.dart'; +import 'package:mirai/src/utils/log.dart'; + +class MiraiNetworkService { + const MiraiNetworkService._(); + + static late Dio _dio; + + static void initialize(Dio dio) => _dio = dio; + + static Future request( + MiraiNetworkRequest request, + BuildContext context, + ) { + switch (request.method) { + case Method.get: + return getRequest(request); + case Method.post: + return postRequest(request, context); + case Method.put: + return putRequest(request); + case Method.delete: + return deleteRequest(request); + } + } + + static Future getRequest(MiraiNetworkRequest request) { + return _dio.get( + request.url, + data: request.data, + queryParameters: request.queryParameters, + options: Options( + contentType: request.contentType, + headers: request.headers, + ), + ); + } + + static Future postRequest( + MiraiNetworkRequest request, + BuildContext context, + ) async { + final body = await _getBody(context, request.data); + return _dio.post( + request.url, + data: body, + queryParameters: request.queryParameters, + options: Options( + contentType: request.contentType, + headers: request.headers, + ), + ); + } + + static Future putRequest(MiraiNetworkRequest request) async { + return _dio.put( + request.url, + data: request.data, + queryParameters: request.queryParameters, + options: Options( + contentType: request.contentType, + headers: request.headers, + ), + ); + } + + static Future deleteRequest(MiraiNetworkRequest request) async { + return _dio.delete( + request.url, + data: request.data, + queryParameters: request.queryParameters, + options: Options( + contentType: request.contentType, + headers: request.headers, + ), + ); + } + + static Future> _getBody( + BuildContext context, + Map? body, + ) async { + Map finalBody = {}; + if (body != null) { + body.forEach((key, value) async { + if (value is Map && value['actionType'] == "getFormDataValue") { + Log.d("This is getFormDataValue"); + + final String formValue = await Future.value( + Mirai.onCallFromJson(value as Map, context) + as String, + ); + Log.d("formValue: $formValue"); + finalBody[key] = formValue; + } else { + finalBody[key] = value; + } + }); + } + + return finalBody; + } +} diff --git a/packages/mirai/lib/src/services/services.dart b/packages/mirai/lib/src/services/services.dart new file mode 100644 index 00000000..68279e3a --- /dev/null +++ b/packages/mirai/lib/src/services/services.dart @@ -0,0 +1,3 @@ +library services; + +export 'mirai_network_service.dart'; diff --git a/packages/mirai/lib/src/utils/action_type.dart b/packages/mirai/lib/src/utils/action_type.dart index 5cf54e09..c8eee0bd 100644 --- a/packages/mirai/lib/src/utils/action_type.dart +++ b/packages/mirai/lib/src/utils/action_type.dart @@ -1,7 +1,6 @@ enum ActionType { navigate, - none, - request, + networkRequest, showModalBottomSheet, showDialog, } diff --git a/packages/mirai/pubspec.yaml b/packages/mirai/pubspec.yaml index 951f0e0d..2fadb2ef 100644 --- a/packages/mirai/pubspec.yaml +++ b/packages/mirai/pubspec.yaml @@ -11,7 +11,6 @@ dependencies: flutter: sdk: flutter freezed_annotation: ^2.2.0 - flutter_bloc: ^8.1.2 json_annotation: ^4.8.1 logger: ^1.4.0 dio: ^5.2.0+1 From b62120a7c6a3373cf07812e7026aba1bac4e634c Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Thu, 21 Sep 2023 10:58:23 +0400 Subject: [PATCH 02/29] Added `MiraiNetworkResult` type in mirai/network_request to handle different statuses of an api response --- .../assets/json/home_screen.json | 34 ++++ .../assets/json/sign_in_screen.json | 77 +++++++- .../assets/json/user_profile_screen.json | 43 +++++ .../lib/app/home/home_screen.dart | 2 +- .../mirai_network_request.dart | 2 + .../mirai_network_request.freezed.dart | 45 ++++- .../mirai_network_request.g.dart | 6 + .../mirai_network_request_parser.dart | 18 +- .../mirai_network_result.dart | 15 ++ .../mirai_network_result.freezed.dart | 179 ++++++++++++++++++ .../mirai_network_result.g.dart | 21 ++ 11 files changed, 424 insertions(+), 18 deletions(-) create mode 100644 examples/mirai_gallery/assets/json/user_profile_screen.json create mode 100644 packages/mirai/lib/src/action_parsers/mirai_network_result/mirai_network_result.dart create mode 100644 packages/mirai/lib/src/action_parsers/mirai_network_result/mirai_network_result.freezed.dart create mode 100644 packages/mirai/lib/src/action_parsers/mirai_network_result/mirai_network_result.g.dart diff --git a/examples/mirai_gallery/assets/json/home_screen.json b/examples/mirai_gallery/assets/json/home_screen.json index 1eb21465..d6c9735c 100644 --- a/examples/mirai_gallery/assets/json/home_screen.json +++ b/examples/mirai_gallery/assets/json/home_screen.json @@ -923,6 +923,40 @@ } } }, + { + "type": "listTile", + "leading": { + "type": "icon", + "iconType": "material", + "icon": "login" + }, + "title": { + "type": "text", + "data": "Mirai User SignIn", + "align": "center", + "style": { + "fontSize": 21 + } + }, + "subtitle": { + "type": "text", + "data": "How to fetch a response from an API and navigate to a new Screen", + "align": "center", + "style": { + "fontSize": 12 + } + }, + "isThreeLine": true, + "style": "list", + "onTap": { + "actionType": "navigate", + "navigationStyle": "push", + "widgetJson": { + "type": "exampleScreen", + "assetPath": "assets/json/sign_in_screen.json" + } + } + }, { "type": "listTile", "leading": { diff --git a/examples/mirai_gallery/assets/json/sign_in_screen.json b/examples/mirai_gallery/assets/json/sign_in_screen.json index a407e7dd..53e4ec02 100644 --- a/examples/mirai_gallery/assets/json/sign_in_screen.json +++ b/examples/mirai_gallery/assets/json/sign_in_screen.json @@ -99,18 +99,87 @@ }, "onPressed": { "actionType": "networkRequest", - "url": "https://dummyjson.com/auth/login", + "url": "https://demo-identity.securrency.com/connect/token", "method": "post", "headers": { - "Content-Type": "application/json" + "contentType": "application/x-www-form-urlencoded" }, + "contentType": "application/x-www-form-urlencoded", "data": { "username": { "actionType": "getFormDataValue", "id": "email" }, - "password": "0lelplR" - } + "password": { + "actionType": "getFormDataValue", + "id": "password" + }, + "client_id": "mobile", + "scope": "openid email roles profile identity.public identity.admin entity securrency.finance securrency.exchange securrency.ens", + "grant_type": "mobile" + }, + "results": [ + { + "statusCode": 200, + "action": { + "actionType": "navigate", + "navigationStyle": "pushReplacement", + "assetPath": "assets/json/user_profile_screen.json" + } + }, + { + "statusCode": 400, + "action": { + "actionType": "showDialog", + "widget": { + "type": "alertDialog", + "titlePadding": { + "top": 8, + "left": 12, + "right": 12 + }, + "contentPadding": { + "top": 8, + "left": 12, + "right": 12 + }, + "title": { + "type": "text", + "data": "Failed to SignIn", + "align": "center", + "style": { + "fontSize": 21 + } + }, + "content": { + "type": "text", + "data": "Invalid username or password.", + "align": "center", + "style": { + "fontSize": 14 + } + }, + "actions": [ + { + "type": "textButton", + "child": { + "type": "text", + "data": "OK" + }, + "onPressed": { + "actionType": "navigate", + "navigationStyle": "pop" + } + }, + { + "type": "sizedBox", + "width": 12 + } + ] + } + } + } + ] } } ] diff --git a/examples/mirai_gallery/assets/json/user_profile_screen.json b/examples/mirai_gallery/assets/json/user_profile_screen.json new file mode 100644 index 00000000..851e713f --- /dev/null +++ b/examples/mirai_gallery/assets/json/user_profile_screen.json @@ -0,0 +1,43 @@ +{ + "type": "scaffold", + "resizeToAvoidBottomInset": false, + "appBar": { + "type": "appBar", + "title": { + "type": "text", + "data": "Welcome!" + } + }, + "body": { + "type": "column", + "crossAxisAlignment": "start", + "children": [ + { + "type": "expanded", + "child": { + "type": "padding", + "padding": { + "top": 24, + "left": 24, + "right": 24, + "bottom": 24 + }, + "child": { + "type": "column", + "children": [ + { + "type": "text", + "data": "You will see your profile details here.", + "textAlign": "center", + "style": { + "fontSize": 16, + "fontWeight": "w400" + } + } + ] + } + } + } + ] + } +} \ No newline at end of file diff --git a/examples/mirai_gallery/lib/app/home/home_screen.dart b/examples/mirai_gallery/lib/app/home/home_screen.dart index 73d92bd1..e337d096 100644 --- a/examples/mirai_gallery/lib/app/home/home_screen.dart +++ b/examples/mirai_gallery/lib/app/home/home_screen.dart @@ -6,6 +6,6 @@ class HomeScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return Mirai.fromAssets('assets/json/sign_in_screen.json') ?? const SizedBox(); + return Mirai.fromAssets('assets/json/home_screen.json') ?? const SizedBox(); } } diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart index 7455e292..81f98e25 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart @@ -1,4 +1,5 @@ import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:mirai/src/action_parsers/mirai_network_result/mirai_network_result.dart'; part 'mirai_network_request.freezed.dart'; part 'mirai_network_request.g.dart'; @@ -19,6 +20,7 @@ class MiraiNetworkRequest with _$MiraiNetworkRequest { Map? headers, String? contentType, Map? data, + @Default([]) List results, }) = _MiraiNetworkRequest; factory MiraiNetworkRequest.fromJson(Map json) => diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart index 78f9a5ea..0869e302 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart @@ -27,6 +27,7 @@ mixin _$MiraiNetworkRequest { Map? get headers => throw _privateConstructorUsedError; String? get contentType => throw _privateConstructorUsedError; Map? get data => throw _privateConstructorUsedError; + List get results => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) @@ -46,7 +47,8 @@ abstract class $MiraiNetworkRequestCopyWith<$Res> { Map? queryParameters, Map? headers, String? contentType, - Map? data}); + Map? data, + List results}); } /// @nodoc @@ -68,6 +70,7 @@ class _$MiraiNetworkRequestCopyWithImpl<$Res, $Val extends MiraiNetworkRequest> Object? headers = freezed, Object? contentType = freezed, Object? data = freezed, + Object? results = null, }) { return _then(_value.copyWith( url: null == url @@ -94,6 +97,10 @@ class _$MiraiNetworkRequestCopyWithImpl<$Res, $Val extends MiraiNetworkRequest> ? _value.data : data // ignore: cast_nullable_to_non_nullable as Map?, + results: null == results + ? _value.results + : results // ignore: cast_nullable_to_non_nullable + as List, ) as $Val); } } @@ -112,7 +119,8 @@ abstract class _$$_MiraiNetworkRequestCopyWith<$Res> Map? queryParameters, Map? headers, String? contentType, - Map? data}); + Map? data, + List results}); } /// @nodoc @@ -132,6 +140,7 @@ class __$$_MiraiNetworkRequestCopyWithImpl<$Res> Object? headers = freezed, Object? contentType = freezed, Object? data = freezed, + Object? results = null, }) { return _then(_$_MiraiNetworkRequest( url: null == url @@ -158,6 +167,10 @@ class __$$_MiraiNetworkRequestCopyWithImpl<$Res> ? _value._data : data // ignore: cast_nullable_to_non_nullable as Map?, + results: null == results + ? _value._results + : results // ignore: cast_nullable_to_non_nullable + as List, )); } } @@ -171,10 +184,12 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { final Map? queryParameters, final Map? headers, this.contentType, - final Map? data}) + final Map? data, + final List results = const []}) : _queryParameters = queryParameters, _headers = headers, - _data = data; + _data = data, + _results = results; factory _$_MiraiNetworkRequest.fromJson(Map json) => _$$_MiraiNetworkRequestFromJson(json); @@ -216,9 +231,18 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { return EqualUnmodifiableMapView(value); } + final List _results; + @override + @JsonKey() + List get results { + if (_results is EqualUnmodifiableListView) return _results; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_results); + } + @override String toString() { - return 'MiraiNetworkRequest(url: $url, method: $method, queryParameters: $queryParameters, headers: $headers, contentType: $contentType, data: $data)'; + return 'MiraiNetworkRequest(url: $url, method: $method, queryParameters: $queryParameters, headers: $headers, contentType: $contentType, data: $data, results: $results)'; } @override @@ -233,7 +257,8 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { const DeepCollectionEquality().equals(other._headers, _headers) && (identical(other.contentType, contentType) || other.contentType == contentType) && - const DeepCollectionEquality().equals(other._data, _data)); + const DeepCollectionEquality().equals(other._data, _data) && + const DeepCollectionEquality().equals(other._results, _results)); } @JsonKey(ignore: true) @@ -245,7 +270,8 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { const DeepCollectionEquality().hash(_queryParameters), const DeepCollectionEquality().hash(_headers), contentType, - const DeepCollectionEquality().hash(_data)); + const DeepCollectionEquality().hash(_data), + const DeepCollectionEquality().hash(_results)); @JsonKey(ignore: true) @override @@ -269,7 +295,8 @@ abstract class _MiraiNetworkRequest implements MiraiNetworkRequest { final Map? queryParameters, final Map? headers, final String? contentType, - final Map? data}) = _$_MiraiNetworkRequest; + final Map? data, + final List results}) = _$_MiraiNetworkRequest; factory _MiraiNetworkRequest.fromJson(Map json) = _$_MiraiNetworkRequest.fromJson; @@ -287,6 +314,8 @@ abstract class _MiraiNetworkRequest implements MiraiNetworkRequest { @override Map? get data; @override + List get results; + @override @JsonKey(ignore: true) _$$_MiraiNetworkRequestCopyWith<_$_MiraiNetworkRequest> get copyWith => throw _privateConstructorUsedError; diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart index 7c2d5e72..42aa126a 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart @@ -16,6 +16,11 @@ _$_MiraiNetworkRequest _$$_MiraiNetworkRequestFromJson( headers: json['headers'] as Map?, contentType: json['contentType'] as String?, data: json['data'] as Map?, + results: (json['results'] as List?) + ?.map( + (e) => MiraiNetworkResult.fromJson(e as Map)) + .toList() ?? + const [], ); Map _$$_MiraiNetworkRequestToJson( @@ -27,6 +32,7 @@ Map _$$_MiraiNetworkRequestToJson( 'headers': instance.headers, 'contentType': instance.contentType, 'data': instance.data, + 'results': instance.results, }; const _$MethodEnumMap = { diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart index b86dba1f..7f54ca3b 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart @@ -1,11 +1,11 @@ import 'dart:async'; +import 'package:dio/dio.dart'; import 'package:flutter/widgets.dart'; import 'package:mirai/mirai.dart'; import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; import 'package:mirai/src/services/mirai_network_service.dart'; import 'package:mirai/src/utils/action_type.dart'; -import 'package:mirai/src/utils/log.dart'; class MiraiNetworkRequestParser extends MiraiActionParser { const MiraiNetworkRequestParser(); @@ -19,9 +19,17 @@ class MiraiNetworkRequestParser extends MiraiActionParser { @override FutureOr onCall(BuildContext context, MiraiNetworkRequest model) async { - Log.d(model); - final result = await MiraiNetworkService.request(model, context); - Log.d(result); - return result; + Response? response; + try { + response = await MiraiNetworkService.request(model, context); + } on DioException catch (e) { + response = e.response; + } + + final expectedResult = model.results + .firstWhere((result) => response?.statusCode == result.statusCode); + + return Mirai.onCallFromJson( + expectedResult.action, context.mounted ? context : context); } } diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_result/mirai_network_result.dart b/packages/mirai/lib/src/action_parsers/mirai_network_result/mirai_network_result.dart new file mode 100644 index 00000000..62eed003 --- /dev/null +++ b/packages/mirai/lib/src/action_parsers/mirai_network_result/mirai_network_result.dart @@ -0,0 +1,15 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'mirai_network_result.freezed.dart'; +part 'mirai_network_result.g.dart'; + +@freezed +class MiraiNetworkResult with _$MiraiNetworkResult { + const factory MiraiNetworkResult({ + required int statusCode, + required Map action, + }) = _MiraiNetworkResult; + + factory MiraiNetworkResult.fromJson(Map json) => + _$MiraiNetworkResultFromJson(json); +} diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_result/mirai_network_result.freezed.dart b/packages/mirai/lib/src/action_parsers/mirai_network_result/mirai_network_result.freezed.dart new file mode 100644 index 00000000..d8d08451 --- /dev/null +++ b/packages/mirai/lib/src/action_parsers/mirai_network_result/mirai_network_result.freezed.dart @@ -0,0 +1,179 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'mirai_network_result.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +MiraiNetworkResult _$MiraiNetworkResultFromJson(Map json) { + return _MiraiNetworkResult.fromJson(json); +} + +/// @nodoc +mixin _$MiraiNetworkResult { + int get statusCode => throw _privateConstructorUsedError; + Map get action => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $MiraiNetworkResultCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MiraiNetworkResultCopyWith<$Res> { + factory $MiraiNetworkResultCopyWith( + MiraiNetworkResult value, $Res Function(MiraiNetworkResult) then) = + _$MiraiNetworkResultCopyWithImpl<$Res, MiraiNetworkResult>; + @useResult + $Res call({int statusCode, Map action}); +} + +/// @nodoc +class _$MiraiNetworkResultCopyWithImpl<$Res, $Val extends MiraiNetworkResult> + implements $MiraiNetworkResultCopyWith<$Res> { + _$MiraiNetworkResultCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? statusCode = null, + Object? action = null, + }) { + return _then(_value.copyWith( + statusCode: null == statusCode + ? _value.statusCode + : statusCode // ignore: cast_nullable_to_non_nullable + as int, + action: null == action + ? _value.action + : action // ignore: cast_nullable_to_non_nullable + as Map, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$_MiraiNetworkResultCopyWith<$Res> + implements $MiraiNetworkResultCopyWith<$Res> { + factory _$$_MiraiNetworkResultCopyWith(_$_MiraiNetworkResult value, + $Res Function(_$_MiraiNetworkResult) then) = + __$$_MiraiNetworkResultCopyWithImpl<$Res>; + @override + @useResult + $Res call({int statusCode, Map action}); +} + +/// @nodoc +class __$$_MiraiNetworkResultCopyWithImpl<$Res> + extends _$MiraiNetworkResultCopyWithImpl<$Res, _$_MiraiNetworkResult> + implements _$$_MiraiNetworkResultCopyWith<$Res> { + __$$_MiraiNetworkResultCopyWithImpl( + _$_MiraiNetworkResult _value, $Res Function(_$_MiraiNetworkResult) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? statusCode = null, + Object? action = null, + }) { + return _then(_$_MiraiNetworkResult( + statusCode: null == statusCode + ? _value.statusCode + : statusCode // ignore: cast_nullable_to_non_nullable + as int, + action: null == action + ? _value._action + : action // ignore: cast_nullable_to_non_nullable + as Map, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_MiraiNetworkResult implements _MiraiNetworkResult { + const _$_MiraiNetworkResult( + {required this.statusCode, required final Map action}) + : _action = action; + + factory _$_MiraiNetworkResult.fromJson(Map json) => + _$$_MiraiNetworkResultFromJson(json); + + @override + final int statusCode; + final Map _action; + @override + Map get action { + if (_action is EqualUnmodifiableMapView) return _action; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(_action); + } + + @override + String toString() { + return 'MiraiNetworkResult(statusCode: $statusCode, action: $action)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_MiraiNetworkResult && + (identical(other.statusCode, statusCode) || + other.statusCode == statusCode) && + const DeepCollectionEquality().equals(other._action, _action)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash( + runtimeType, statusCode, const DeepCollectionEquality().hash(_action)); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_MiraiNetworkResultCopyWith<_$_MiraiNetworkResult> get copyWith => + __$$_MiraiNetworkResultCopyWithImpl<_$_MiraiNetworkResult>( + this, _$identity); + + @override + Map toJson() { + return _$$_MiraiNetworkResultToJson( + this, + ); + } +} + +abstract class _MiraiNetworkResult implements MiraiNetworkResult { + const factory _MiraiNetworkResult( + {required final int statusCode, + required final Map action}) = _$_MiraiNetworkResult; + + factory _MiraiNetworkResult.fromJson(Map json) = + _$_MiraiNetworkResult.fromJson; + + @override + int get statusCode; + @override + Map get action; + @override + @JsonKey(ignore: true) + _$$_MiraiNetworkResultCopyWith<_$_MiraiNetworkResult> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_result/mirai_network_result.g.dart b/packages/mirai/lib/src/action_parsers/mirai_network_result/mirai_network_result.g.dart new file mode 100644 index 00000000..af9df5f2 --- /dev/null +++ b/packages/mirai/lib/src/action_parsers/mirai_network_result/mirai_network_result.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mirai_network_result.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_MiraiNetworkResult _$$_MiraiNetworkResultFromJson( + Map json) => + _$_MiraiNetworkResult( + statusCode: json['statusCode'] as int, + action: json['action'] as Map, + ); + +Map _$$_MiraiNetworkResultToJson( + _$_MiraiNetworkResult instance) => + { + 'statusCode': instance.statusCode, + 'action': instance.action, + }; From 39689cd92958538854bbdb7293cf8c937b01999b Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Thu, 21 Sep 2023 12:29:28 +0400 Subject: [PATCH 03/29] Removed `signin` example for home screen json --- .../assets/json/home_screen.json | 34 ------------------- .../assets/json/sign_in_screen.json | 3 -- 2 files changed, 37 deletions(-) diff --git a/examples/mirai_gallery/assets/json/home_screen.json b/examples/mirai_gallery/assets/json/home_screen.json index d6c9735c..1eb21465 100644 --- a/examples/mirai_gallery/assets/json/home_screen.json +++ b/examples/mirai_gallery/assets/json/home_screen.json @@ -923,40 +923,6 @@ } } }, - { - "type": "listTile", - "leading": { - "type": "icon", - "iconType": "material", - "icon": "login" - }, - "title": { - "type": "text", - "data": "Mirai User SignIn", - "align": "center", - "style": { - "fontSize": 21 - } - }, - "subtitle": { - "type": "text", - "data": "How to fetch a response from an API and navigate to a new Screen", - "align": "center", - "style": { - "fontSize": 12 - } - }, - "isThreeLine": true, - "style": "list", - "onTap": { - "actionType": "navigate", - "navigationStyle": "push", - "widgetJson": { - "type": "exampleScreen", - "assetPath": "assets/json/sign_in_screen.json" - } - } - }, { "type": "listTile", "leading": { diff --git a/examples/mirai_gallery/assets/json/sign_in_screen.json b/examples/mirai_gallery/assets/json/sign_in_screen.json index 53e4ec02..1523bfde 100644 --- a/examples/mirai_gallery/assets/json/sign_in_screen.json +++ b/examples/mirai_gallery/assets/json/sign_in_screen.json @@ -101,9 +101,6 @@ "actionType": "networkRequest", "url": "https://demo-identity.securrency.com/connect/token", "method": "post", - "headers": { - "contentType": "application/x-www-form-urlencoded" - }, "contentType": "application/x-www-form-urlencoded", "data": { "username": { From 082d3cf47cd004c8d0f7301740e3cc783880913c Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Thu, 21 Sep 2023 16:32:38 +0400 Subject: [PATCH 04/29] Fix network-request model export in mirai/action_parsers --- packages/mirai/lib/src/action_parsers/action_parsers.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/mirai/lib/src/action_parsers/action_parsers.dart b/packages/mirai/lib/src/action_parsers/action_parsers.dart index 17dbd876..e6cd6f68 100644 --- a/packages/mirai/lib/src/action_parsers/action_parsers.dart +++ b/packages/mirai/lib/src/action_parsers/action_parsers.dart @@ -2,3 +2,4 @@ export 'package:mirai/src/action_parsers/mirai_dialog_action/mirai_dialog_action export 'package:mirai/src/action_parsers/mirai_form_data/mirai_form_data.dart'; export 'package:mirai/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action_parser.dart'; export 'package:mirai/src/action_parsers/mirai_navigate/mirai_navigate_action_parser.dart'; +export 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; From 442a7835c85813217254974ac160b4d175ab6ccc Mon Sep 17 00:00:00 2001 From: Divyanshu Bhargava Date: Fri, 22 Sep 2023 12:41:48 +0400 Subject: [PATCH 05/29] fix: Remove "initialValue" passing into TextFormField as it's paased in the controller. --- .../mirai_text_form_field/mirai_text_form_field_parser.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart b/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart index 7f03bd5f..334f43be 100644 --- a/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart @@ -76,7 +76,6 @@ class _TextFormFieldWidgetState extends State<_TextFormFieldWidget> { // ); } }, - initialValue: widget.model.initialValue, keyboardType: widget.model.keyboardType?.value, textInputAction: widget.model.textInputAction, textCapitalization: widget.model.textCapitalization, From 2cc84710c6f2e7fd6880397b39ce91a5cce1b7c4 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Fri, 22 Sep 2023 14:51:54 +0400 Subject: [PATCH 06/29] Added export for action models and parsers in mirai/action_parsers --- packages/mirai/lib/src/action_parsers/action_parsers.dart | 7 ++++--- .../mirai_dialog_action/mirai_dialog_action.dart | 2 -- .../mirai_dialog_action/mirai_dialog_action_parser.dart | 2 ++ .../mirai_form_data/mirai_form_data_parser.dart | 2 ++ .../mirai_navigate/mirai_navigate_action_parser.dart | 2 ++ .../mirai_network_request_parser.dart | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/mirai/lib/src/action_parsers/action_parsers.dart b/packages/mirai/lib/src/action_parsers/action_parsers.dart index e6cd6f68..95d53e88 100644 --- a/packages/mirai/lib/src/action_parsers/action_parsers.dart +++ b/packages/mirai/lib/src/action_parsers/action_parsers.dart @@ -1,5 +1,6 @@ -export 'package:mirai/src/action_parsers/mirai_dialog_action/mirai_dialog_action.dart'; -export 'package:mirai/src/action_parsers/mirai_form_data/mirai_form_data.dart'; export 'package:mirai/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action_parser.dart'; export 'package:mirai/src/action_parsers/mirai_navigate/mirai_navigate_action_parser.dart'; -export 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; +export 'package:mirai/src/action_parsers/mirai_dialog_action/mirai_dialog_action_parser.dart'; +export 'package:mirai/src/action_parsers/mirai_form_data/mirai_form_data_parser.dart'; +export 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart'; +export 'package:mirai/src/action_parsers/mirai_network_result/mirai_network_result.dart'; diff --git a/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.dart b/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.dart index 5b67e656..aca00f8c 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action.dart @@ -2,8 +2,6 @@ import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; -export 'mirai_dialog_action_parser.dart'; - part 'mirai_dialog_action.freezed.dart'; part 'mirai_dialog_action.g.dart'; diff --git a/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action_parser.dart index 2c258b3c..9f782394 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action_parser.dart @@ -7,6 +7,8 @@ import 'package:mirai/src/utils/action_type.dart'; import 'package:mirai/src/utils/color_utils.dart'; import 'package:mirai_framework/mirai_framework.dart'; +export 'mirai_dialog_action.dart'; + class MiraiDialogActionParser extends MiraiActionParser { const MiraiDialogActionParser(); diff --git a/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data_parser.dart index b815dd48..1928866a 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_form_data/mirai_form_data_parser.dart @@ -4,6 +4,8 @@ import 'package:mirai/src/parsers/mirai_form/mirai_form_parser.dart'; import 'package:mirai/src/utils/log.dart'; import 'package:mirai_framework/mirai_framework.dart'; +export 'mirai_form_data.dart'; + class MiraiFormDataActionParser extends MiraiActionParser { const MiraiFormDataActionParser(); diff --git a/packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action_parser.dart index 6bfd96e3..f69e5898 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_navigate/mirai_navigate_action_parser.dart @@ -6,6 +6,8 @@ import 'package:mirai/src/framework/framework.dart'; import 'package:mirai/src/utils/action_type.dart'; import 'package:mirai_framework/mirai_framework.dart'; +export 'mirai_navigate_action.dart'; + class MiraiNavigateActionParser extends MiraiActionParser { const MiraiNavigateActionParser(); diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart index 7f54ca3b..1f1c8871 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart @@ -3,10 +3,11 @@ import 'dart:async'; import 'package:dio/dio.dart'; import 'package:flutter/widgets.dart'; import 'package:mirai/mirai.dart'; -import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; import 'package:mirai/src/services/mirai_network_service.dart'; import 'package:mirai/src/utils/action_type.dart'; +export 'mirai_network_request.dart'; + class MiraiNetworkRequestParser extends MiraiActionParser { const MiraiNetworkRequestParser(); From 0de691746922f4a9ac20b96cefc410e6080913cd Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Fri, 22 Sep 2023 18:12:19 +0400 Subject: [PATCH 07/29] Removed repeated imports from framework/mirai.dart --- packages/mirai/lib/src/framework/mirai.dart | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/mirai/lib/src/framework/mirai.dart b/packages/mirai/lib/src/framework/mirai.dart index bde6cec9..3e59a06e 100644 --- a/packages/mirai/lib/src/framework/mirai.dart +++ b/packages/mirai/lib/src/framework/mirai.dart @@ -5,9 +5,6 @@ import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:mirai/src/action_parsers/action_parsers.dart'; -import 'package:mirai/src/action_parsers/mirai_form_data/mirai_form_data_parser.dart'; -import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; -import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart'; import 'package:mirai/src/framework/mirai_registry.dart'; import 'package:mirai/src/parsers/mirai_center/mirai_center_parser.dart'; import 'package:mirai/src/parsers/mirai_check_box_widget/mirai_check_box_widget_parser.dart'; From 9676eb717dd2edd6fbe7e832b49329b65ee9b2e9 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Fri, 22 Sep 2023 18:43:58 +0400 Subject: [PATCH 08/29] Converted request body to dynamic type to handle `List` in apis like KYC submit and renamed it to `body` --- .../assets/json/sign_in_screen.json | 2 +- .../mirai_network_request.dart | 2 +- .../mirai_network_request.freezed.dart | 49 +++++++---------- .../mirai_network_request.g.dart | 4 +- .../mirai_network_request_parser.dart | 1 - packages/mirai/lib/src/framework/mirai.dart | 1 - .../src/services/mirai_network_service.dart | 53 +++++++++++-------- 7 files changed, 56 insertions(+), 56 deletions(-) diff --git a/examples/mirai_gallery/assets/json/sign_in_screen.json b/examples/mirai_gallery/assets/json/sign_in_screen.json index 1523bfde..8b030cef 100644 --- a/examples/mirai_gallery/assets/json/sign_in_screen.json +++ b/examples/mirai_gallery/assets/json/sign_in_screen.json @@ -102,7 +102,7 @@ "url": "https://demo-identity.securrency.com/connect/token", "method": "post", "contentType": "application/x-www-form-urlencoded", - "data": { + "body": { "username": { "actionType": "getFormDataValue", "id": "email" diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart index 81f98e25..2cbdee30 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart @@ -19,7 +19,7 @@ class MiraiNetworkRequest with _$MiraiNetworkRequest { Map? queryParameters, Map? headers, String? contentType, - Map? data, + dynamic body, @Default([]) List results, }) = _MiraiNetworkRequest; diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart index 0869e302..0774955b 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart @@ -26,7 +26,7 @@ mixin _$MiraiNetworkRequest { throw _privateConstructorUsedError; Map? get headers => throw _privateConstructorUsedError; String? get contentType => throw _privateConstructorUsedError; - Map? get data => throw _privateConstructorUsedError; + dynamic get body => throw _privateConstructorUsedError; List get results => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @@ -47,7 +47,7 @@ abstract class $MiraiNetworkRequestCopyWith<$Res> { Map? queryParameters, Map? headers, String? contentType, - Map? data, + dynamic body, List results}); } @@ -69,7 +69,7 @@ class _$MiraiNetworkRequestCopyWithImpl<$Res, $Val extends MiraiNetworkRequest> Object? queryParameters = freezed, Object? headers = freezed, Object? contentType = freezed, - Object? data = freezed, + Object? body = freezed, Object? results = null, }) { return _then(_value.copyWith( @@ -93,10 +93,10 @@ class _$MiraiNetworkRequestCopyWithImpl<$Res, $Val extends MiraiNetworkRequest> ? _value.contentType : contentType // ignore: cast_nullable_to_non_nullable as String?, - data: freezed == data - ? _value.data - : data // ignore: cast_nullable_to_non_nullable - as Map?, + body: freezed == body + ? _value.body + : body // ignore: cast_nullable_to_non_nullable + as dynamic, results: null == results ? _value.results : results // ignore: cast_nullable_to_non_nullable @@ -119,7 +119,7 @@ abstract class _$$_MiraiNetworkRequestCopyWith<$Res> Map? queryParameters, Map? headers, String? contentType, - Map? data, + dynamic body, List results}); } @@ -139,7 +139,7 @@ class __$$_MiraiNetworkRequestCopyWithImpl<$Res> Object? queryParameters = freezed, Object? headers = freezed, Object? contentType = freezed, - Object? data = freezed, + Object? body = freezed, Object? results = null, }) { return _then(_$_MiraiNetworkRequest( @@ -163,10 +163,10 @@ class __$$_MiraiNetworkRequestCopyWithImpl<$Res> ? _value.contentType : contentType // ignore: cast_nullable_to_non_nullable as String?, - data: freezed == data - ? _value._data - : data // ignore: cast_nullable_to_non_nullable - as Map?, + body: freezed == body + ? _value.body + : body // ignore: cast_nullable_to_non_nullable + as dynamic, results: null == results ? _value._results : results // ignore: cast_nullable_to_non_nullable @@ -184,11 +184,10 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { final Map? queryParameters, final Map? headers, this.contentType, - final Map? data, + this.body, final List results = const []}) : _queryParameters = queryParameters, _headers = headers, - _data = data, _results = results; factory _$_MiraiNetworkRequest.fromJson(Map json) => @@ -221,16 +220,8 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { @override final String? contentType; - final Map? _data; @override - Map? get data { - final value = _data; - if (value == null) return null; - if (_data is EqualUnmodifiableMapView) return _data; - // ignore: implicit_dynamic_type - return EqualUnmodifiableMapView(value); - } - + final dynamic body; final List _results; @override @JsonKey() @@ -242,7 +233,7 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { @override String toString() { - return 'MiraiNetworkRequest(url: $url, method: $method, queryParameters: $queryParameters, headers: $headers, contentType: $contentType, data: $data, results: $results)'; + return 'MiraiNetworkRequest(url: $url, method: $method, queryParameters: $queryParameters, headers: $headers, contentType: $contentType, body: $body, results: $results)'; } @override @@ -257,7 +248,7 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { const DeepCollectionEquality().equals(other._headers, _headers) && (identical(other.contentType, contentType) || other.contentType == contentType) && - const DeepCollectionEquality().equals(other._data, _data) && + const DeepCollectionEquality().equals(other.body, body) && const DeepCollectionEquality().equals(other._results, _results)); } @@ -270,7 +261,7 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { const DeepCollectionEquality().hash(_queryParameters), const DeepCollectionEquality().hash(_headers), contentType, - const DeepCollectionEquality().hash(_data), + const DeepCollectionEquality().hash(body), const DeepCollectionEquality().hash(_results)); @JsonKey(ignore: true) @@ -295,7 +286,7 @@ abstract class _MiraiNetworkRequest implements MiraiNetworkRequest { final Map? queryParameters, final Map? headers, final String? contentType, - final Map? data, + final dynamic body, final List results}) = _$_MiraiNetworkRequest; factory _MiraiNetworkRequest.fromJson(Map json) = @@ -312,7 +303,7 @@ abstract class _MiraiNetworkRequest implements MiraiNetworkRequest { @override String? get contentType; @override - Map? get data; + dynamic get body; @override List get results; @override diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart index 42aa126a..8db8dc02 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart @@ -15,7 +15,7 @@ _$_MiraiNetworkRequest _$$_MiraiNetworkRequestFromJson( queryParameters: json['queryParameters'] as Map?, headers: json['headers'] as Map?, contentType: json['contentType'] as String?, - data: json['data'] as Map?, + body: json['body'], results: (json['results'] as List?) ?.map( (e) => MiraiNetworkResult.fromJson(e as Map)) @@ -31,7 +31,7 @@ Map _$$_MiraiNetworkRequestToJson( 'queryParameters': instance.queryParameters, 'headers': instance.headers, 'contentType': instance.contentType, - 'data': instance.data, + 'body': instance.body, 'results': instance.results, }; diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart index 7f54ca3b..73c39681 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart @@ -3,7 +3,6 @@ import 'dart:async'; import 'package:dio/dio.dart'; import 'package:flutter/widgets.dart'; import 'package:mirai/mirai.dart'; -import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; import 'package:mirai/src/services/mirai_network_service.dart'; import 'package:mirai/src/utils/action_type.dart'; diff --git a/packages/mirai/lib/src/framework/mirai.dart b/packages/mirai/lib/src/framework/mirai.dart index bde6cec9..3934a2e1 100644 --- a/packages/mirai/lib/src/framework/mirai.dart +++ b/packages/mirai/lib/src/framework/mirai.dart @@ -6,7 +6,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:mirai/src/action_parsers/action_parsers.dart'; import 'package:mirai/src/action_parsers/mirai_form_data/mirai_form_data_parser.dart'; -import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart'; import 'package:mirai/src/framework/mirai_registry.dart'; import 'package:mirai/src/parsers/mirai_center/mirai_center_parser.dart'; diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index 6a308b7f..0063eae8 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -30,7 +30,7 @@ class MiraiNetworkService { static Future getRequest(MiraiNetworkRequest request) { return _dio.get( request.url, - data: request.data, + data: request.body, queryParameters: request.queryParameters, options: Options( contentType: request.contentType, @@ -43,7 +43,7 @@ class MiraiNetworkService { MiraiNetworkRequest request, BuildContext context, ) async { - final body = await _getBody(context, request.data); + final body = await _getBody(context, request.body); return _dio.post( request.url, data: body, @@ -58,7 +58,7 @@ class MiraiNetworkService { static Future putRequest(MiraiNetworkRequest request) async { return _dio.put( request.url, - data: request.data, + data: request.body, queryParameters: request.queryParameters, options: Options( contentType: request.contentType, @@ -70,7 +70,7 @@ class MiraiNetworkService { static Future deleteRequest(MiraiNetworkRequest request) async { return _dio.delete( request.url, - data: request.data, + data: request.body, queryParameters: request.queryParameters, options: Options( contentType: request.contentType, @@ -79,28 +79,39 @@ class MiraiNetworkService { ); } - static Future> _getBody( + static Future _getBody( BuildContext context, - Map? body, + dynamic body, ) async { - Map finalBody = {}; if (body != null) { - body.forEach((key, value) async { - if (value is Map && value['actionType'] == "getFormDataValue") { - Log.d("This is getFormDataValue"); + if (body is Map) { + Map finalBody = {}; - final String formValue = await Future.value( - Mirai.onCallFromJson(value as Map, context) - as String, - ); - Log.d("formValue: $formValue"); - finalBody[key] = formValue; - } else { - finalBody[key] = value; + body.forEach((key, value) async { + if (value is Map && value['actionType'] == "getFormDataValue") { + Log.d("This is getFormDataValue"); + + final String formValue = await Future.value( + Mirai.onCallFromJson(value as Map, context) + as String, + ); + Log.d("formValue: $formValue"); + finalBody[key] = formValue; + } else { + finalBody[key] = value; + } + }); + + return finalBody; + } else if (body is List) { + List finalBody = []; + for (dynamic value in body) { + final result = await _getBody(context, value); + finalBody.add(result); } - }); - } - return finalBody; + return finalBody; + } + } } } From 56f400d5442d6e9386f5dfead11e1889d0edf5be Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Mon, 25 Sep 2023 16:46:48 +0400 Subject: [PATCH 09/29] Exported `services` in mirai framework --- packages/mirai/lib/mirai.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/mirai/lib/mirai.dart b/packages/mirai/lib/mirai.dart index 40e2acd2..6aac5829 100644 --- a/packages/mirai/lib/mirai.dart +++ b/packages/mirai/lib/mirai.dart @@ -5,3 +5,4 @@ export 'package:mirai/src/framework/framework.dart'; export 'package:mirai/src/parsers/parsers.dart'; export 'package:mirai/src/utils/utils.dart'; export 'package:mirai_framework/mirai_framework.dart'; +export 'package:mirai/src/services/services.dart'; From c3961dd112c048fdf23214f4a63b8911444b2820 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Tue, 26 Sep 2023 12:56:06 +0400 Subject: [PATCH 10/29] fixed body return in `mirai_network_service` in case of body other than list and map --- packages/mirai/lib/src/services/mirai_network_service.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index 0063eae8..1b428557 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -111,6 +111,8 @@ class MiraiNetworkService { } return finalBody; + } else { + return body; } } } From 4ac1982ce3b00b4d8823693f5c66cf3925372012 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Tue, 26 Sep 2023 13:05:04 +0400 Subject: [PATCH 11/29] Added body type converted to MultipartFile in case of a file in the request body --- .../mirai/lib/src/services/mirai_network_service.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index 1b428557..0ee60b52 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request.dart'; @@ -97,6 +99,13 @@ class MiraiNetworkService { ); Log.d("formValue: $formValue"); finalBody[key] = formValue; + } else if (value is File) { + String fileName = value.path.split('/').last; + FormData formData = FormData.fromMap({ + key: await MultipartFile.fromFile(value.path, filename: fileName), + }); + + return Future.value(formData); } else { finalBody[key] = value; } From b38ac87c54b24287d27ca5ea1868d840be3841a6 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Tue, 26 Sep 2023 15:09:47 +0400 Subject: [PATCH 12/29] Fixed form data return in json body builder in mirai_network_service --- packages/mirai/lib/src/services/mirai_network_service.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index 0ee60b52..e06a243e 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -105,7 +105,7 @@ class MiraiNetworkService { key: await MultipartFile.fromFile(value.path, filename: fileName), }); - return Future.value(formData); + finalBody[key] = formData; } else { finalBody[key] = value; } From 2578f9194a5c9c69de32d9c9e7d1f1a45cdbcea2 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Tue, 26 Sep 2023 15:28:36 +0400 Subject: [PATCH 13/29] Refactored mirai network service and added future.wait in get body --- .../mirai_network_request_parser.dart | 1 - .../lib/src/services/mirai_network_service.dart | 13 +++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart index 1f1c8871..4fb881ec 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart @@ -3,7 +3,6 @@ import 'dart:async'; import 'package:dio/dio.dart'; import 'package:flutter/widgets.dart'; import 'package:mirai/mirai.dart'; -import 'package:mirai/src/services/mirai_network_service.dart'; import 'package:mirai/src/utils/action_type.dart'; export 'mirai_network_request.dart'; diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index e06a243e..19094f0b 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -87,9 +87,10 @@ class MiraiNetworkService { ) async { if (body != null) { if (body is Map) { - Map finalBody = {}; + dynamic finalBody = {}; - body.forEach((key, value) async { + await Future.forEach(body.keys, (key) async { + final value = body[key]; if (value is Map && value['actionType'] == "getFormDataValue") { Log.d("This is getFormDataValue"); @@ -98,14 +99,18 @@ class MiraiNetworkService { as String, ); Log.d("formValue: $formValue"); + finalBody[key] = formValue; } else if (value is File) { String fileName = value.path.split('/').last; + final multipart = + await MultipartFile.fromFile(value.path, filename: fileName); + FormData formData = FormData.fromMap({ - key: await MultipartFile.fromFile(value.path, filename: fileName), + key: multipart, }); - finalBody[key] = formData; + finalBody = formData; } else { finalBody[key] = value; } From a52f734ed0fe5b00dc874dcaa835ab8417c94945 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Wed, 27 Sep 2023 11:14:50 +0400 Subject: [PATCH 14/29] Fixed load values from any action in json body construction in Mirai form JSON --- packages/mirai/lib/src/services/mirai_network_service.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index 19094f0b..167c55b6 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -91,14 +91,14 @@ class MiraiNetworkService { await Future.forEach(body.keys, (key) async { final value = body[key]; - if (value is Map && value['actionType'] == "getFormDataValue") { - Log.d("This is getFormDataValue"); + if (value is Map && value.containsKey('actionType')) { + Log.d("Loading from an action callback"); final String formValue = await Future.value( Mirai.onCallFromJson(value as Map, context) as String, ); - Log.d("formValue: $formValue"); + Log.d("Loaded value from the callback: $formValue"); finalBody[key] = formValue; } else if (value is File) { From e3f2d4d622865386124a1975b42b9a2f6b4186fc Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Wed, 27 Sep 2023 12:52:29 +0400 Subject: [PATCH 15/29] Renamed values of `finalBody` to `callbackValue` in `netwrok_service` --- packages/mirai/lib/src/services/mirai_network_service.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index 167c55b6..de3ff440 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -94,13 +94,13 @@ class MiraiNetworkService { if (value is Map && value.containsKey('actionType')) { Log.d("Loading from an action callback"); - final String formValue = await Future.value( + final String callbackValue = await Future.value( Mirai.onCallFromJson(value as Map, context) as String, ); - Log.d("Loaded value from the callback: $formValue"); + Log.d("Loaded value from the callback: $callbackValue"); - finalBody[key] = formValue; + finalBody[key] = callbackValue; } else if (value is File) { String fileName = value.path.split('/').last; final multipart = From 400b071f88a1f02632418eb3a50fff4517949370 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Wed, 27 Sep 2023 14:25:00 +0400 Subject: [PATCH 16/29] Updated Future.value from `onCallFromJson` type to dynamic in case if it fails or returns null --- packages/mirai/lib/src/services/mirai_network_service.dart | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index de3ff440..89ff9a27 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -94,9 +94,8 @@ class MiraiNetworkService { if (value is Map && value.containsKey('actionType')) { Log.d("Loading from an action callback"); - final String callbackValue = await Future.value( - Mirai.onCallFromJson(value as Map, context) - as String, + final dynamic callbackValue = await Future.value( + Mirai.onCallFromJson(value as Map, context), ); Log.d("Loaded value from the callback: $callbackValue"); From 72c839610f8d6b8dbdb292fa2c5b18ad760b68cc Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Wed, 27 Sep 2023 14:46:47 +0400 Subject: [PATCH 17/29] Added response check for value !=null in `network_request_parser` --- examples/mirai_gallery/assets/json/sign_in_screen.json | 4 ++-- .../mirai_network_request_parser.dart | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/mirai_gallery/assets/json/sign_in_screen.json b/examples/mirai_gallery/assets/json/sign_in_screen.json index 8b030cef..652ed9c2 100644 --- a/examples/mirai_gallery/assets/json/sign_in_screen.json +++ b/examples/mirai_gallery/assets/json/sign_in_screen.json @@ -95,7 +95,7 @@ "type": "elevatedButton", "child": { "type": "text", - "data": "Sign In 1" + "data": "Sign In" }, "onPressed": { "actionType": "networkRequest", @@ -121,7 +121,7 @@ "action": { "actionType": "navigate", "navigationStyle": "pushReplacement", - "assetPath": "assets/json/user_profile_screen.json" + "assetPath": "assets/jsons/kyc_intro_screen.json" } }, { diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart index 4fb881ec..c5da410f 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart @@ -26,10 +26,12 @@ class MiraiNetworkRequestParser extends MiraiActionParser { response = e.response; } - final expectedResult = model.results - .firstWhere((result) => response?.statusCode == result.statusCode); + if (response != null) { + final expectedResult = model.results + .firstWhere((result) => response?.statusCode == result.statusCode); - return Mirai.onCallFromJson( - expectedResult.action, context.mounted ? context : context); + return Mirai.onCallFromJson( + expectedResult.action, context.mounted ? context : context); + } } } From 8aa1a4aa963b9ba28b9e520dd680d8a1c4ac7efd Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Wed, 27 Sep 2023 16:08:37 +0400 Subject: [PATCH 18/29] Refactored update body json in `mirai_network_service` for deep into every obj of the json --- .../assets/json/sign_in_screen.json | 2 +- .../src/services/mirai_network_service.dart | 111 ++++++++++++------ 2 files changed, 79 insertions(+), 34 deletions(-) diff --git a/examples/mirai_gallery/assets/json/sign_in_screen.json b/examples/mirai_gallery/assets/json/sign_in_screen.json index 652ed9c2..7a5d565f 100644 --- a/examples/mirai_gallery/assets/json/sign_in_screen.json +++ b/examples/mirai_gallery/assets/json/sign_in_screen.json @@ -121,7 +121,7 @@ "action": { "actionType": "navigate", "navigationStyle": "pushReplacement", - "assetPath": "assets/jsons/kyc_intro_screen.json" + "assetPath": "assets/json/user_profile_screen.json" } }, { diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index 89ff9a27..1c44e789 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -45,10 +45,10 @@ class MiraiNetworkService { MiraiNetworkRequest request, BuildContext context, ) async { - final body = await _getBody(context, request.body); + await _updateBody(context, request.body); return _dio.post( request.url, - data: body, + data: request.body, queryParameters: request.queryParameters, options: Options( contentType: request.contentType, @@ -81,52 +81,97 @@ class MiraiNetworkService { ); } - static Future _getBody( + static Future _updateBody( BuildContext context, dynamic body, ) async { if (body != null) { - if (body is Map) { - dynamic finalBody = {}; - - await Future.forEach(body.keys, (key) async { - final value = body[key]; - if (value is Map && value.containsKey('actionType')) { + for (dynamic mapEntry in body.entries) { + final key = mapEntry.key; + final value = mapEntry.value; + if (value is Map && value.containsKey('actionType')) { + try { Log.d("Loading from an action callback"); final dynamic callbackValue = await Future.value( Mirai.onCallFromJson(value as Map, context), ); - Log.d("Loaded value from the callback: $callbackValue"); - - finalBody[key] = callbackValue; - } else if (value is File) { - String fileName = value.path.split('/').last; - final multipart = - await MultipartFile.fromFile(value.path, filename: fileName); - FormData formData = FormData.fromMap({ - key: multipart, - }); + body.update( + key, + (existingValue) => callbackValue, + ); - finalBody = formData; - } else { - finalBody[key] = value; + continue; + } catch (e) { + Log.e(e); } - }); - - return finalBody; - } else if (body is List) { - List finalBody = []; - for (dynamic value in body) { - final result = await _getBody(context, value); - finalBody.add(result); + } else if (value is File) { + String fileName = value.path.split('/').last; + final multipart = + await MultipartFile.fromFile(value.path, filename: fileName); + + FormData formData = FormData.fromMap({ + key: multipart, + }); + + return formData; } - return finalBody; - } else { - return body; + if (mapEntry.value is Map) { + _updateBody(context.mounted ? context : context, mapEntry.value); + } + + if (mapEntry.value is List) { + for (Map listItem in mapEntry.value) { + _updateBody(context.mounted ? context : context, listItem); + } + } } + + // dynamic finalBody = {}; + + // await Future.forEach(body.keys, (key) async { + // final value = body[key]; + // if (value is Map && value.containsKey('actionType')) { + // Log.d("Loading from an action callback"); + + // final dynamic callbackValue = await Future.value( + // Mirai.onCallFromJson(value as Map, context), + // ); + // Log.d("Loaded value from the callback: $callbackValue"); + + // finalBody[key] = callbackValue; + // } else if (value is File) { + // String fileName = value.path.split('/').last; + // final multipart = + // await MultipartFile.fromFile(value.path, filename: fileName); + + // FormData formData = FormData.fromMap({ + // key: multipart, + // }); + + // finalBody = formData; + // } else { + // finalBody[key] = value; + // } + // }); + + // return finalBody; + } + + // else if (body is List) { + // // List finalBody = []; + // // for (dynamic value in body) { + // // final result = await _getBody(context, value); + // // finalBody.add(result); + // // } + + // // return finalBody; + // } + + else { + return body; } } } From 86e5c3982d1442bc6395356e034777f8439b414c Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Wed, 27 Sep 2023 16:59:57 +0400 Subject: [PATCH 19/29] Updated body from json in `mirai_network_service` to handle list of body items --- .../src/services/mirai_network_service.dart | 59 ++++--------------- 1 file changed, 13 insertions(+), 46 deletions(-) diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index 1c44e789..786edea9 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -45,10 +45,10 @@ class MiraiNetworkService { MiraiNetworkRequest request, BuildContext context, ) async { - await _updateBody(context, request.body); + final body = await _updateBody(context, request.body); return _dio.post( request.url, - data: request.body, + data: body, queryParameters: request.queryParameters, options: Options( contentType: request.contentType, @@ -85,7 +85,7 @@ class MiraiNetworkService { BuildContext context, dynamic body, ) async { - if (body != null) { + if (body is Map) { for (dynamic mapEntry in body.entries) { final key = mapEntry.key; final value = mapEntry.value; @@ -115,7 +115,8 @@ class MiraiNetworkService { key: multipart, }); - return formData; + body = formData; + break; } if (mapEntry.value is Map) { @@ -128,50 +129,16 @@ class MiraiNetworkService { } } } + } else if (body is List) { + List updatedList = []; + for (dynamic value in body) { + final updatedValue = await _updateBody(context, value); + updatedList.add(updatedValue); + } - // dynamic finalBody = {}; - - // await Future.forEach(body.keys, (key) async { - // final value = body[key]; - // if (value is Map && value.containsKey('actionType')) { - // Log.d("Loading from an action callback"); - - // final dynamic callbackValue = await Future.value( - // Mirai.onCallFromJson(value as Map, context), - // ); - // Log.d("Loaded value from the callback: $callbackValue"); - - // finalBody[key] = callbackValue; - // } else if (value is File) { - // String fileName = value.path.split('/').last; - // final multipart = - // await MultipartFile.fromFile(value.path, filename: fileName); - - // FormData formData = FormData.fromMap({ - // key: multipart, - // }); - - // finalBody = formData; - // } else { - // finalBody[key] = value; - // } - // }); - - // return finalBody; + body = updatedList; } - // else if (body is List) { - // // List finalBody = []; - // // for (dynamic value in body) { - // // final result = await _getBody(context, value); - // // finalBody.add(result); - // // } - - // // return finalBody; - // } - - else { - return body; - } + return body; } } From 1db557d81a20822d55659764f71faec56ad3c4b1 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Thu, 28 Sep 2023 11:25:55 +0400 Subject: [PATCH 20/29] Added default case for status-code not provided --- .../mirai_network_request_parser.dart | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart index c5da410f..5894f294 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart @@ -26,9 +26,35 @@ class MiraiNetworkRequestParser extends MiraiActionParser { response = e.response; } - if (response != null) { - final expectedResult = model.results - .firstWhere((result) => response?.statusCode == result.statusCode); + if (response != null && response.statusCode != null) { + final expectedResult = model.results.firstWhere( + (result) => response?.statusCode == result.statusCode, + orElse: () => MiraiNetworkResult( + statusCode: response?.statusCode ?? 0, + action: { + "actionType": "showDialog", + "widget": { + "type": "alertDialog", + "title": { + "type": "text", + "data": response?.statusMessage, + "align": "center", + "style": {"fontSize": 18} + }, + "content": { + "type": "padding", + "padding": {"top": 8, "left": 12, "right": 12, "bottom": 8}, + "child": { + "type": "text", + "data": response?.data, + "align": "center", + "style": {"fontSize": 12} + } + } + } + }, + ), + ); return Mirai.onCallFromJson( expectedResult.action, context.mounted ? context : context); From 0ee5d7d10736f19782be471ffb23d8546043a558 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Mon, 2 Oct 2023 12:34:19 +0400 Subject: [PATCH 21/29] Updated response message and title in network_request_parser --- .../mirai_network_request_parser.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart index 5894f294..fc9eba7c 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart @@ -37,17 +37,17 @@ class MiraiNetworkRequestParser extends MiraiActionParser { "type": "alertDialog", "title": { "type": "text", - "data": response?.statusMessage, - "align": "center", + "data": "${response?.statusMessage} - ${response?.statusCode}", + "textAlign": "center", "style": {"fontSize": 18} }, "content": { "type": "padding", - "padding": {"top": 8, "left": 12, "right": 12, "bottom": 8}, + "padding": {"top": 8, "left": 12, "right": 12, "bottom": 12}, "child": { "type": "text", - "data": response?.data, - "align": "center", + "data": "${response?.data}", + "textAlign": "center", "style": {"fontSize": 12} } } From 0feb06fe0307d15ed3f4fc3f8d6aaaccf299f23f Mon Sep 17 00:00:00 2001 From: Divyanshu Bhargava Date: Wed, 4 Oct 2023 15:42:07 +0400 Subject: [PATCH 22/29] Add logs in MiraiNetworkRequestParser --- .../mirai_network_request/mirai_network_request_parser.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart index 1f1c8871..b4566d33 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart @@ -3,8 +3,8 @@ import 'dart:async'; import 'package:dio/dio.dart'; import 'package:flutter/widgets.dart'; import 'package:mirai/mirai.dart'; -import 'package:mirai/src/services/mirai_network_service.dart'; import 'package:mirai/src/utils/action_type.dart'; +import 'package:mirai/src/utils/log.dart'; export 'mirai_network_request.dart'; @@ -23,8 +23,10 @@ class MiraiNetworkRequestParser extends MiraiActionParser { Response? response; try { response = await MiraiNetworkService.request(model, context); + Log.d(response); } on DioException catch (e) { response = e.response; + Log.e(e.response); } final expectedResult = model.results From 998839feb3e8389d0868e25e8ad63fa7b1e24603 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Mon, 9 Oct 2023 12:24:52 +0400 Subject: [PATCH 23/29] refactor: Updated netowrk headers to be taken from the storage or any custom action --- packages/mirai/lib/src/services/mirai_network_service.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index 786edea9..4e59a5ed 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -46,13 +46,15 @@ class MiraiNetworkService { BuildContext context, ) async { final body = await _updateBody(context, request.body); + final headers = + await _updateBody(context.mounted ? context : context, request.headers); return _dio.post( request.url, data: body, queryParameters: request.queryParameters, options: Options( contentType: request.contentType, - headers: request.headers, + headers: headers, ), ); } From 5ec07a41177cf2d796a16f2e220db5d6c8926ce9 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Mon, 9 Oct 2023 12:50:46 +0400 Subject: [PATCH 24/29] refactor: Updated `headers` type to dynamic from `map` --- .../mirai_network_request.dart | 2 +- .../mirai_network_request.freezed.dart | 33 +++++++------------ .../mirai_network_request.g.dart | 2 +- .../src/services/mirai_network_service.dart | 20 ++++------- 4 files changed, 20 insertions(+), 37 deletions(-) diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart index 2cbdee30..d007e8e3 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart @@ -17,7 +17,7 @@ class MiraiNetworkRequest with _$MiraiNetworkRequest { required String url, @Default(Method.get) Method method, Map? queryParameters, - Map? headers, + dynamic headers, String? contentType, dynamic body, @Default([]) List results, diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart index 0774955b..386dd201 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart @@ -24,7 +24,7 @@ mixin _$MiraiNetworkRequest { Method get method => throw _privateConstructorUsedError; Map? get queryParameters => throw _privateConstructorUsedError; - Map? get headers => throw _privateConstructorUsedError; + dynamic get headers => throw _privateConstructorUsedError; String? get contentType => throw _privateConstructorUsedError; dynamic get body => throw _privateConstructorUsedError; List get results => throw _privateConstructorUsedError; @@ -45,7 +45,7 @@ abstract class $MiraiNetworkRequestCopyWith<$Res> { {String url, Method method, Map? queryParameters, - Map? headers, + dynamic headers, String? contentType, dynamic body, List results}); @@ -88,7 +88,7 @@ class _$MiraiNetworkRequestCopyWithImpl<$Res, $Val extends MiraiNetworkRequest> headers: freezed == headers ? _value.headers : headers // ignore: cast_nullable_to_non_nullable - as Map?, + as dynamic, contentType: freezed == contentType ? _value.contentType : contentType // ignore: cast_nullable_to_non_nullable @@ -117,7 +117,7 @@ abstract class _$$_MiraiNetworkRequestCopyWith<$Res> {String url, Method method, Map? queryParameters, - Map? headers, + dynamic headers, String? contentType, dynamic body, List results}); @@ -156,9 +156,9 @@ class __$$_MiraiNetworkRequestCopyWithImpl<$Res> : queryParameters // ignore: cast_nullable_to_non_nullable as Map?, headers: freezed == headers - ? _value._headers + ? _value.headers : headers // ignore: cast_nullable_to_non_nullable - as Map?, + as dynamic, contentType: freezed == contentType ? _value.contentType : contentType // ignore: cast_nullable_to_non_nullable @@ -182,12 +182,11 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { {required this.url, this.method = Method.get, final Map? queryParameters, - final Map? headers, + this.headers, this.contentType, this.body, final List results = const []}) : _queryParameters = queryParameters, - _headers = headers, _results = results; factory _$_MiraiNetworkRequest.fromJson(Map json) => @@ -208,16 +207,8 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { return EqualUnmodifiableMapView(value); } - final Map? _headers; @override - Map? get headers { - final value = _headers; - if (value == null) return null; - if (_headers is EqualUnmodifiableMapView) return _headers; - // ignore: implicit_dynamic_type - return EqualUnmodifiableMapView(value); - } - + final dynamic headers; @override final String? contentType; @override @@ -245,7 +236,7 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { (identical(other.method, method) || other.method == method) && const DeepCollectionEquality() .equals(other._queryParameters, _queryParameters) && - const DeepCollectionEquality().equals(other._headers, _headers) && + const DeepCollectionEquality().equals(other.headers, headers) && (identical(other.contentType, contentType) || other.contentType == contentType) && const DeepCollectionEquality().equals(other.body, body) && @@ -259,7 +250,7 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { url, method, const DeepCollectionEquality().hash(_queryParameters), - const DeepCollectionEquality().hash(_headers), + const DeepCollectionEquality().hash(headers), contentType, const DeepCollectionEquality().hash(body), const DeepCollectionEquality().hash(_results)); @@ -284,7 +275,7 @@ abstract class _MiraiNetworkRequest implements MiraiNetworkRequest { {required final String url, final Method method, final Map? queryParameters, - final Map? headers, + final dynamic headers, final String? contentType, final dynamic body, final List results}) = _$_MiraiNetworkRequest; @@ -299,7 +290,7 @@ abstract class _MiraiNetworkRequest implements MiraiNetworkRequest { @override Map? get queryParameters; @override - Map? get headers; + dynamic get headers; @override String? get contentType; @override diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart index 8db8dc02..9a4942bd 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart @@ -13,7 +13,7 @@ _$_MiraiNetworkRequest _$$_MiraiNetworkRequestFromJson( method: $enumDecodeNullable(_$MethodEnumMap, json['method']) ?? Method.get, queryParameters: json['queryParameters'] as Map?, - headers: json['headers'] as Map?, + headers: json['headers'], contentType: json['contentType'] as String?, body: json['body'], results: (json['results'] as List?) diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index 4e59a5ed..6c52e515 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -92,22 +92,14 @@ class MiraiNetworkService { final key = mapEntry.key; final value = mapEntry.value; if (value is Map && value.containsKey('actionType')) { - try { - Log.d("Loading from an action callback"); + Log.d("Loading from an action callback"); - final dynamic callbackValue = await Future.value( - Mirai.onCallFromJson(value as Map, context), - ); + final dynamic callbackValue = await Future.value( + Mirai.onCallFromJson(value as Map, context), + ); - body.update( - key, - (existingValue) => callbackValue, - ); - - continue; - } catch (e) { - Log.e(e); - } + body[key] = callbackValue; + continue; } else if (value is File) { String fileName = value.path.split('/').last; final multipart = From 8b0012316e4450d543983be74ebb15180845119d Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Mon, 9 Oct 2023 14:39:18 +0400 Subject: [PATCH 25/29] refactor: Updated webview.freezed and webview.generated files --- .../src/services/mirai_network_service.dart | 5 ++- .../mirai_webview/mirai_webview.freezed.dart | 42 +++++++++---------- .../mirai_webview/mirai_webview.g.dart | 6 +-- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index 6c52e515..eff97dbf 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -46,8 +46,9 @@ class MiraiNetworkService { BuildContext context, ) async { final body = await _updateBody(context, request.body); - final headers = - await _updateBody(context.mounted ? context : context, request.headers); + + Map headers = Map.from(request.headers); + headers = await _updateBody(context.mounted ? context : context, headers); return _dio.post( request.url, data: body, diff --git a/packages/mirai_webview/lib/parsers/mirai_webview/mirai_webview.freezed.dart b/packages/mirai_webview/lib/parsers/mirai_webview/mirai_webview.freezed.dart index 419ed802..4e956d39 100644 --- a/packages/mirai_webview/lib/parsers/mirai_webview/mirai_webview.freezed.dart +++ b/packages/mirai_webview/lib/parsers/mirai_webview/mirai_webview.freezed.dart @@ -91,11 +91,11 @@ class _$MiraiWebViewCopyWithImpl<$Res, $Val extends MiraiWebView> } /// @nodoc -abstract class _$$_MiraiWebViewCopyWith<$Res> +abstract class _$$MiraiWebViewImplCopyWith<$Res> implements $MiraiWebViewCopyWith<$Res> { - factory _$$_MiraiWebViewCopyWith( - _$_MiraiWebView value, $Res Function(_$_MiraiWebView) then) = - __$$_MiraiWebViewCopyWithImpl<$Res>; + factory _$$MiraiWebViewImplCopyWith( + _$MiraiWebViewImpl value, $Res Function(_$MiraiWebViewImpl) then) = + __$$MiraiWebViewImplCopyWithImpl<$Res>; @override @useResult $Res call( @@ -107,11 +107,11 @@ abstract class _$$_MiraiWebViewCopyWith<$Res> } /// @nodoc -class __$$_MiraiWebViewCopyWithImpl<$Res> - extends _$MiraiWebViewCopyWithImpl<$Res, _$_MiraiWebView> - implements _$$_MiraiWebViewCopyWith<$Res> { - __$$_MiraiWebViewCopyWithImpl( - _$_MiraiWebView _value, $Res Function(_$_MiraiWebView) _then) +class __$$MiraiWebViewImplCopyWithImpl<$Res> + extends _$MiraiWebViewCopyWithImpl<$Res, _$MiraiWebViewImpl> + implements _$$MiraiWebViewImplCopyWith<$Res> { + __$$MiraiWebViewImplCopyWithImpl( + _$MiraiWebViewImpl _value, $Res Function(_$MiraiWebViewImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -123,7 +123,7 @@ class __$$_MiraiWebViewCopyWithImpl<$Res> Object? userAgent = freezed, Object? enableZoom = null, }) { - return _then(_$_MiraiWebView( + return _then(_$MiraiWebViewImpl( url: null == url ? _value.url : url // ignore: cast_nullable_to_non_nullable @@ -150,16 +150,16 @@ class __$$_MiraiWebViewCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$_MiraiWebView implements _MiraiWebView { - const _$_MiraiWebView( +class _$MiraiWebViewImpl implements _MiraiWebView { + const _$MiraiWebViewImpl( {required this.url, this.javaScriptMode = JavaScriptMode.unrestricted, this.backgroundColor = "#000000", this.userAgent, this.enableZoom = false}); - factory _$_MiraiWebView.fromJson(Map json) => - _$$_MiraiWebViewFromJson(json); + factory _$MiraiWebViewImpl.fromJson(Map json) => + _$$MiraiWebViewImplFromJson(json); @override final String url; @@ -184,7 +184,7 @@ class _$_MiraiWebView implements _MiraiWebView { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$_MiraiWebView && + other is _$MiraiWebViewImpl && (identical(other.url, url) || other.url == url) && (identical(other.javaScriptMode, javaScriptMode) || other.javaScriptMode == javaScriptMode) && @@ -204,12 +204,12 @@ class _$_MiraiWebView implements _MiraiWebView { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$_MiraiWebViewCopyWith<_$_MiraiWebView> get copyWith => - __$$_MiraiWebViewCopyWithImpl<_$_MiraiWebView>(this, _$identity); + _$$MiraiWebViewImplCopyWith<_$MiraiWebViewImpl> get copyWith => + __$$MiraiWebViewImplCopyWithImpl<_$MiraiWebViewImpl>(this, _$identity); @override Map toJson() { - return _$$_MiraiWebViewToJson( + return _$$MiraiWebViewImplToJson( this, ); } @@ -221,10 +221,10 @@ abstract class _MiraiWebView implements MiraiWebView { final JavaScriptMode javaScriptMode, final String backgroundColor, final String? userAgent, - final bool enableZoom}) = _$_MiraiWebView; + final bool enableZoom}) = _$MiraiWebViewImpl; factory _MiraiWebView.fromJson(Map json) = - _$_MiraiWebView.fromJson; + _$MiraiWebViewImpl.fromJson; @override String get url; @@ -238,6 +238,6 @@ abstract class _MiraiWebView implements MiraiWebView { bool get enableZoom; @override @JsonKey(ignore: true) - _$$_MiraiWebViewCopyWith<_$_MiraiWebView> get copyWith => + _$$MiraiWebViewImplCopyWith<_$MiraiWebViewImpl> get copyWith => throw _privateConstructorUsedError; } diff --git a/packages/mirai_webview/lib/parsers/mirai_webview/mirai_webview.g.dart b/packages/mirai_webview/lib/parsers/mirai_webview/mirai_webview.g.dart index 3ef18f8e..a1f6c50d 100644 --- a/packages/mirai_webview/lib/parsers/mirai_webview/mirai_webview.g.dart +++ b/packages/mirai_webview/lib/parsers/mirai_webview/mirai_webview.g.dart @@ -6,8 +6,8 @@ part of 'mirai_webview.dart'; // JsonSerializableGenerator // ************************************************************************** -_$_MiraiWebView _$$_MiraiWebViewFromJson(Map json) => - _$_MiraiWebView( +_$MiraiWebViewImpl _$$MiraiWebViewImplFromJson(Map json) => + _$MiraiWebViewImpl( url: json['url'] as String, javaScriptMode: $enumDecodeNullable( _$JavaScriptModeEnumMap, json['javaScriptMode']) ?? @@ -17,7 +17,7 @@ _$_MiraiWebView _$$_MiraiWebViewFromJson(Map json) => enableZoom: json['enableZoom'] as bool? ?? false, ); -Map _$$_MiraiWebViewToJson(_$_MiraiWebView instance) => +Map _$$MiraiWebViewImplToJson(_$MiraiWebViewImpl instance) => { 'url': instance.url, 'javaScriptMode': _$JavaScriptModeEnumMap[instance.javaScriptMode]!, From 7583248148f99ae3bcaeaa0a91c6789745bda589 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Mon, 9 Oct 2023 14:56:16 +0400 Subject: [PATCH 26/29] refactor: Network request headers type changed to map --- .../mirai_network_request.dart | 2 +- .../mirai_network_request.freezed.dart | 33 ++++++++++++------- .../mirai_network_request.g.dart | 2 +- .../src/services/mirai_network_service.dart | 3 +- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart index d007e8e3..2cbdee30 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.dart @@ -17,7 +17,7 @@ class MiraiNetworkRequest with _$MiraiNetworkRequest { required String url, @Default(Method.get) Method method, Map? queryParameters, - dynamic headers, + Map? headers, String? contentType, dynamic body, @Default([]) List results, diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart index 386dd201..0774955b 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.freezed.dart @@ -24,7 +24,7 @@ mixin _$MiraiNetworkRequest { Method get method => throw _privateConstructorUsedError; Map? get queryParameters => throw _privateConstructorUsedError; - dynamic get headers => throw _privateConstructorUsedError; + Map? get headers => throw _privateConstructorUsedError; String? get contentType => throw _privateConstructorUsedError; dynamic get body => throw _privateConstructorUsedError; List get results => throw _privateConstructorUsedError; @@ -45,7 +45,7 @@ abstract class $MiraiNetworkRequestCopyWith<$Res> { {String url, Method method, Map? queryParameters, - dynamic headers, + Map? headers, String? contentType, dynamic body, List results}); @@ -88,7 +88,7 @@ class _$MiraiNetworkRequestCopyWithImpl<$Res, $Val extends MiraiNetworkRequest> headers: freezed == headers ? _value.headers : headers // ignore: cast_nullable_to_non_nullable - as dynamic, + as Map?, contentType: freezed == contentType ? _value.contentType : contentType // ignore: cast_nullable_to_non_nullable @@ -117,7 +117,7 @@ abstract class _$$_MiraiNetworkRequestCopyWith<$Res> {String url, Method method, Map? queryParameters, - dynamic headers, + Map? headers, String? contentType, dynamic body, List results}); @@ -156,9 +156,9 @@ class __$$_MiraiNetworkRequestCopyWithImpl<$Res> : queryParameters // ignore: cast_nullable_to_non_nullable as Map?, headers: freezed == headers - ? _value.headers + ? _value._headers : headers // ignore: cast_nullable_to_non_nullable - as dynamic, + as Map?, contentType: freezed == contentType ? _value.contentType : contentType // ignore: cast_nullable_to_non_nullable @@ -182,11 +182,12 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { {required this.url, this.method = Method.get, final Map? queryParameters, - this.headers, + final Map? headers, this.contentType, this.body, final List results = const []}) : _queryParameters = queryParameters, + _headers = headers, _results = results; factory _$_MiraiNetworkRequest.fromJson(Map json) => @@ -207,8 +208,16 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { return EqualUnmodifiableMapView(value); } + final Map? _headers; @override - final dynamic headers; + Map? get headers { + final value = _headers; + if (value == null) return null; + if (_headers is EqualUnmodifiableMapView) return _headers; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); + } + @override final String? contentType; @override @@ -236,7 +245,7 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { (identical(other.method, method) || other.method == method) && const DeepCollectionEquality() .equals(other._queryParameters, _queryParameters) && - const DeepCollectionEquality().equals(other.headers, headers) && + const DeepCollectionEquality().equals(other._headers, _headers) && (identical(other.contentType, contentType) || other.contentType == contentType) && const DeepCollectionEquality().equals(other.body, body) && @@ -250,7 +259,7 @@ class _$_MiraiNetworkRequest implements _MiraiNetworkRequest { url, method, const DeepCollectionEquality().hash(_queryParameters), - const DeepCollectionEquality().hash(headers), + const DeepCollectionEquality().hash(_headers), contentType, const DeepCollectionEquality().hash(body), const DeepCollectionEquality().hash(_results)); @@ -275,7 +284,7 @@ abstract class _MiraiNetworkRequest implements MiraiNetworkRequest { {required final String url, final Method method, final Map? queryParameters, - final dynamic headers, + final Map? headers, final String? contentType, final dynamic body, final List results}) = _$_MiraiNetworkRequest; @@ -290,7 +299,7 @@ abstract class _MiraiNetworkRequest implements MiraiNetworkRequest { @override Map? get queryParameters; @override - dynamic get headers; + Map? get headers; @override String? get contentType; @override diff --git a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart index 9a4942bd..8db8dc02 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_network_request/mirai_network_request.g.dart @@ -13,7 +13,7 @@ _$_MiraiNetworkRequest _$$_MiraiNetworkRequestFromJson( method: $enumDecodeNullable(_$MethodEnumMap, json['method']) ?? Method.get, queryParameters: json['queryParameters'] as Map?, - headers: json['headers'], + headers: json['headers'] as Map?, contentType: json['contentType'] as String?, body: json['body'], results: (json['results'] as List?) diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index eff97dbf..7f523536 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -47,7 +47,8 @@ class MiraiNetworkService { ) async { final body = await _updateBody(context, request.body); - Map headers = Map.from(request.headers); + Map headers = + Map.from(request.headers ?? {}); headers = await _updateBody(context.mounted ? context : context, headers); return _dio.post( request.url, From aae897b75983db8e86c3a784cf74d8ec42bd1467 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Tue, 10 Oct 2023 12:53:56 +0400 Subject: [PATCH 27/29] refactor: Updated headers and content-type of dio options in dio initialization --- .../src/services/mirai_network_service.dart | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/packages/mirai/lib/src/services/mirai_network_service.dart b/packages/mirai/lib/src/services/mirai_network_service.dart index 7f523536..5e2c0501 100644 --- a/packages/mirai/lib/src/services/mirai_network_service.dart +++ b/packages/mirai/lib/src/services/mirai_network_service.dart @@ -16,12 +16,18 @@ class MiraiNetworkService { static Future request( MiraiNetworkRequest request, BuildContext context, - ) { + ) async { + Map headers = + Map.from(request.headers ?? {}); + headers = await _updateBody(context.mounted ? context : context, headers); + _dio.options.headers = headers; + _dio.options.contentType = request.contentType; + switch (request.method) { case Method.get: return getRequest(request); case Method.post: - return postRequest(request, context); + return postRequest(request, context.mounted ? context : context); case Method.put: return putRequest(request); case Method.delete: @@ -29,15 +35,11 @@ class MiraiNetworkService { } } - static Future getRequest(MiraiNetworkRequest request) { + static Future getRequest(MiraiNetworkRequest request) async { return _dio.get( request.url, data: request.body, queryParameters: request.queryParameters, - options: Options( - contentType: request.contentType, - headers: request.headers, - ), ); } @@ -54,10 +56,6 @@ class MiraiNetworkService { request.url, data: body, queryParameters: request.queryParameters, - options: Options( - contentType: request.contentType, - headers: headers, - ), ); } @@ -66,10 +64,6 @@ class MiraiNetworkService { request.url, data: request.body, queryParameters: request.queryParameters, - options: Options( - contentType: request.contentType, - headers: request.headers, - ), ); } @@ -78,10 +72,6 @@ class MiraiNetworkService { request.url, data: request.body, queryParameters: request.queryParameters, - options: Options( - contentType: request.contentType, - headers: request.headers, - ), ); } From 486cf146d3b433fb0926619ad6525c874d3980de Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Mon, 23 Oct 2023 16:01:36 +0400 Subject: [PATCH 28/29] fix: Removed imports from `mirai.dart` and rebuilt packages --- examples/mirai_gallery/pubspec.lock | 25 ++++++----- examples/mirai_gallery/pubspec_overrides.yaml | 8 ---- packages/mirai/lib/src/framework/mirai.dart | 2 - .../mirai_align/mirai_align.freezed.dart | 42 +++++++++---------- .../parsers/mirai_align/mirai_align.g.dart | 6 +-- packages/mirai/pubspec_overrides.yaml | 4 -- packages/mirai_webview/pubspec_overrides.yaml | 4 -- 7 files changed, 38 insertions(+), 53 deletions(-) delete mode 100644 examples/mirai_gallery/pubspec_overrides.yaml delete mode 100644 packages/mirai/pubspec_overrides.yaml delete mode 100644 packages/mirai_webview/pubspec_overrides.yaml diff --git a/examples/mirai_gallery/pubspec.lock b/examples/mirai_gallery/pubspec.lock index d79c901e..7546ae9b 100644 --- a/examples/mirai_gallery/pubspec.lock +++ b/examples/mirai_gallery/pubspec.lock @@ -390,23 +390,26 @@ packages: mirai: dependency: "direct main" description: - path: "../../packages/mirai" - relative: true - source: path + name: mirai + sha256: "7c14ce9731f2779f517735402127c03631e7243427e672ea620101ae8e0f1fb4" + url: "https://pub.dev" + source: hosted version: "0.5.1" mirai_framework: - dependency: "direct overridden" + dependency: transitive description: - path: "../../packages/mirai_framework" - relative: true - source: path + name: mirai_framework + sha256: a8fcd5cb782bb054587d7cddcbc688f5f9392017ac0a43f8df6a11872bee98db + url: "https://pub.dev" + source: hosted version: "0.0.2" mirai_webview: dependency: "direct main" description: - path: "../../packages/mirai_webview" - relative: true - source: path + name: mirai_webview + sha256: baf0048263357e1b69e2caa19d43823c96946628443b4f41ae6f5737452cb7dc + url: "https://pub.dev" + source: hosted version: "0.0.2" nested: dependency: transitive @@ -654,5 +657,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.1.0-185.0.dev <4.0.0" + dart: ">=3.1.0 <4.0.0" flutter: ">=3.7.0" diff --git a/examples/mirai_gallery/pubspec_overrides.yaml b/examples/mirai_gallery/pubspec_overrides.yaml deleted file mode 100644 index c1d7530b..00000000 --- a/examples/mirai_gallery/pubspec_overrides.yaml +++ /dev/null @@ -1,8 +0,0 @@ -# melos_managed_dependency_overrides: mirai,mirai_framework,mirai_webview -dependency_overrides: - mirai: - path: ../../packages/mirai - mirai_framework: - path: ../../packages/mirai_framework - mirai_webview: - path: ../../packages/mirai_webview diff --git a/packages/mirai/lib/src/framework/mirai.dart b/packages/mirai/lib/src/framework/mirai.dart index be16f595..1e249b25 100644 --- a/packages/mirai/lib/src/framework/mirai.dart +++ b/packages/mirai/lib/src/framework/mirai.dart @@ -6,8 +6,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:mirai/src/action_parsers/action_parsers.dart'; import 'package:mirai/src/framework/mirai_registry.dart'; -import 'package:mirai/src/network/mirai_network.dart'; -import 'package:mirai/src/network/mirai_request.dart'; import 'package:mirai/src/parsers/mirai_align/mirai_align_parser.dart'; import 'package:mirai/src/parsers/mirai_center/mirai_center_parser.dart'; import 'package:mirai/src/parsers/mirai_check_box_widget/mirai_check_box_widget_parser.dart'; diff --git a/packages/mirai/lib/src/parsers/mirai_align/mirai_align.freezed.dart b/packages/mirai/lib/src/parsers/mirai_align/mirai_align.freezed.dart index c286282e..e5b1cd10 100644 --- a/packages/mirai/lib/src/parsers/mirai_align/mirai_align.freezed.dart +++ b/packages/mirai/lib/src/parsers/mirai_align/mirai_align.freezed.dart @@ -84,11 +84,11 @@ class _$MiraiAlignCopyWithImpl<$Res, $Val extends MiraiAlign> } /// @nodoc -abstract class _$$MiraiAlignImplCopyWith<$Res> +abstract class _$$_MiraiAlignCopyWith<$Res> implements $MiraiAlignCopyWith<$Res> { - factory _$$MiraiAlignImplCopyWith( - _$MiraiAlignImpl value, $Res Function(_$MiraiAlignImpl) then) = - __$$MiraiAlignImplCopyWithImpl<$Res>; + factory _$$_MiraiAlignCopyWith( + _$_MiraiAlign value, $Res Function(_$_MiraiAlign) then) = + __$$_MiraiAlignCopyWithImpl<$Res>; @override @useResult $Res call( @@ -99,11 +99,11 @@ abstract class _$$MiraiAlignImplCopyWith<$Res> } /// @nodoc -class __$$MiraiAlignImplCopyWithImpl<$Res> - extends _$MiraiAlignCopyWithImpl<$Res, _$MiraiAlignImpl> - implements _$$MiraiAlignImplCopyWith<$Res> { - __$$MiraiAlignImplCopyWithImpl( - _$MiraiAlignImpl _value, $Res Function(_$MiraiAlignImpl) _then) +class __$$_MiraiAlignCopyWithImpl<$Res> + extends _$MiraiAlignCopyWithImpl<$Res, _$_MiraiAlign> + implements _$$_MiraiAlignCopyWith<$Res> { + __$$_MiraiAlignCopyWithImpl( + _$_MiraiAlign _value, $Res Function(_$_MiraiAlign) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -114,7 +114,7 @@ class __$$MiraiAlignImplCopyWithImpl<$Res> Object? heightFactor = freezed, Object? child = freezed, }) { - return _then(_$MiraiAlignImpl( + return _then(_$_MiraiAlign( alignment: null == alignment ? _value.alignment : alignment // ignore: cast_nullable_to_non_nullable @@ -137,16 +137,16 @@ class __$$MiraiAlignImplCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$MiraiAlignImpl implements _MiraiAlign { - const _$MiraiAlignImpl( +class _$_MiraiAlign implements _MiraiAlign { + const _$_MiraiAlign( {this.alignment = MiraiAlignmentDirectional.center, this.widthFactor, this.heightFactor, final Map? child}) : _child = child; - factory _$MiraiAlignImpl.fromJson(Map json) => - _$$MiraiAlignImplFromJson(json); + factory _$_MiraiAlign.fromJson(Map json) => + _$$_MiraiAlignFromJson(json); @override @JsonKey() @@ -174,7 +174,7 @@ class _$MiraiAlignImpl implements _MiraiAlign { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$MiraiAlignImpl && + other is _$_MiraiAlign && (identical(other.alignment, alignment) || other.alignment == alignment) && (identical(other.widthFactor, widthFactor) || @@ -192,12 +192,12 @@ class _$MiraiAlignImpl implements _MiraiAlign { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$MiraiAlignImplCopyWith<_$MiraiAlignImpl> get copyWith => - __$$MiraiAlignImplCopyWithImpl<_$MiraiAlignImpl>(this, _$identity); + _$$_MiraiAlignCopyWith<_$_MiraiAlign> get copyWith => + __$$_MiraiAlignCopyWithImpl<_$_MiraiAlign>(this, _$identity); @override Map toJson() { - return _$$MiraiAlignImplToJson( + return _$$_MiraiAlignToJson( this, ); } @@ -208,10 +208,10 @@ abstract class _MiraiAlign implements MiraiAlign { {final MiraiAlignmentDirectional alignment, final double? widthFactor, final double? heightFactor, - final Map? child}) = _$MiraiAlignImpl; + final Map? child}) = _$_MiraiAlign; factory _MiraiAlign.fromJson(Map json) = - _$MiraiAlignImpl.fromJson; + _$_MiraiAlign.fromJson; @override MiraiAlignmentDirectional get alignment; @@ -223,6 +223,6 @@ abstract class _MiraiAlign implements MiraiAlign { Map? get child; @override @JsonKey(ignore: true) - _$$MiraiAlignImplCopyWith<_$MiraiAlignImpl> get copyWith => + _$$_MiraiAlignCopyWith<_$_MiraiAlign> get copyWith => throw _privateConstructorUsedError; } diff --git a/packages/mirai/lib/src/parsers/mirai_align/mirai_align.g.dart b/packages/mirai/lib/src/parsers/mirai_align/mirai_align.g.dart index 6b56d670..4d886f4c 100644 --- a/packages/mirai/lib/src/parsers/mirai_align/mirai_align.g.dart +++ b/packages/mirai/lib/src/parsers/mirai_align/mirai_align.g.dart @@ -6,8 +6,8 @@ part of 'mirai_align.dart'; // JsonSerializableGenerator // ************************************************************************** -_$MiraiAlignImpl _$$MiraiAlignImplFromJson(Map json) => - _$MiraiAlignImpl( +_$_MiraiAlign _$$_MiraiAlignFromJson(Map json) => + _$_MiraiAlign( alignment: $enumDecodeNullable( _$MiraiAlignmentDirectionalEnumMap, json['alignment']) ?? MiraiAlignmentDirectional.center, @@ -16,7 +16,7 @@ _$MiraiAlignImpl _$$MiraiAlignImplFromJson(Map json) => child: json['child'] as Map?, ); -Map _$$MiraiAlignImplToJson(_$MiraiAlignImpl instance) => +Map _$$_MiraiAlignToJson(_$_MiraiAlign instance) => { 'alignment': _$MiraiAlignmentDirectionalEnumMap[instance.alignment]!, 'widthFactor': instance.widthFactor, diff --git a/packages/mirai/pubspec_overrides.yaml b/packages/mirai/pubspec_overrides.yaml deleted file mode 100644 index 9c1a1d25..00000000 --- a/packages/mirai/pubspec_overrides.yaml +++ /dev/null @@ -1,4 +0,0 @@ -# melos_managed_dependency_overrides: mirai_framework -dependency_overrides: - mirai_framework: - path: ../mirai_framework diff --git a/packages/mirai_webview/pubspec_overrides.yaml b/packages/mirai_webview/pubspec_overrides.yaml deleted file mode 100644 index 9c1a1d25..00000000 --- a/packages/mirai_webview/pubspec_overrides.yaml +++ /dev/null @@ -1,4 +0,0 @@ -# melos_managed_dependency_overrides: mirai_framework -dependency_overrides: - mirai_framework: - path: ../mirai_framework From 0daccaf222c0e10d42a5d5d49d6dcc541ca9b5a4 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Wed, 25 Oct 2023 16:15:20 +0400 Subject: [PATCH 29/29] fix: Built framework and example app to fix PR workflow failing (dart format issue) --- .../app/example/example_screen.freezed.dart | 42 ++++++------ .../lib/app/example/example_screen.g.dart | 6 +- examples/mirai_gallery/pubspec.lock | 65 +++++++++---------- examples/mirai_gallery/pubspec_overrides.yaml | 8 +++ packages/mirai/pubspec_overrides.yaml | 4 ++ packages/mirai_webview/pubspec_overrides.yaml | 4 ++ 6 files changed, 71 insertions(+), 58 deletions(-) create mode 100644 examples/mirai_gallery/pubspec_overrides.yaml create mode 100644 packages/mirai/pubspec_overrides.yaml create mode 100644 packages/mirai_webview/pubspec_overrides.yaml diff --git a/examples/mirai_gallery/lib/app/example/example_screen.freezed.dart b/examples/mirai_gallery/lib/app/example/example_screen.freezed.dart index 7a3de3b6..d3ec0faf 100644 --- a/examples/mirai_gallery/lib/app/example/example_screen.freezed.dart +++ b/examples/mirai_gallery/lib/app/example/example_screen.freezed.dart @@ -62,22 +62,22 @@ class _$ExampleScreenCopyWithImpl<$Res, $Val extends ExampleScreen> } /// @nodoc -abstract class _$$_ExampleScreenCopyWith<$Res> +abstract class _$$ExampleScreenImplCopyWith<$Res> implements $ExampleScreenCopyWith<$Res> { - factory _$$_ExampleScreenCopyWith( - _$_ExampleScreen value, $Res Function(_$_ExampleScreen) then) = - __$$_ExampleScreenCopyWithImpl<$Res>; + factory _$$ExampleScreenImplCopyWith( + _$ExampleScreenImpl value, $Res Function(_$ExampleScreenImpl) then) = + __$$ExampleScreenImplCopyWithImpl<$Res>; @override @useResult $Res call({String assetPath}); } /// @nodoc -class __$$_ExampleScreenCopyWithImpl<$Res> - extends _$ExampleScreenCopyWithImpl<$Res, _$_ExampleScreen> - implements _$$_ExampleScreenCopyWith<$Res> { - __$$_ExampleScreenCopyWithImpl( - _$_ExampleScreen _value, $Res Function(_$_ExampleScreen) _then) +class __$$ExampleScreenImplCopyWithImpl<$Res> + extends _$ExampleScreenCopyWithImpl<$Res, _$ExampleScreenImpl> + implements _$$ExampleScreenImplCopyWith<$Res> { + __$$ExampleScreenImplCopyWithImpl( + _$ExampleScreenImpl _value, $Res Function(_$ExampleScreenImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -85,7 +85,7 @@ class __$$_ExampleScreenCopyWithImpl<$Res> $Res call({ Object? assetPath = null, }) { - return _then(_$_ExampleScreen( + return _then(_$ExampleScreenImpl( assetPath: null == assetPath ? _value.assetPath : assetPath // ignore: cast_nullable_to_non_nullable @@ -96,11 +96,11 @@ class __$$_ExampleScreenCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$_ExampleScreen implements _ExampleScreen { - const _$_ExampleScreen({required this.assetPath}); +class _$ExampleScreenImpl implements _ExampleScreen { + const _$ExampleScreenImpl({required this.assetPath}); - factory _$_ExampleScreen.fromJson(Map json) => - _$$_ExampleScreenFromJson(json); + factory _$ExampleScreenImpl.fromJson(Map json) => + _$$ExampleScreenImplFromJson(json); @override final String assetPath; @@ -114,7 +114,7 @@ class _$_ExampleScreen implements _ExampleScreen { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$_ExampleScreen && + other is _$ExampleScreenImpl && (identical(other.assetPath, assetPath) || other.assetPath == assetPath)); } @@ -126,12 +126,12 @@ class _$_ExampleScreen implements _ExampleScreen { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$_ExampleScreenCopyWith<_$_ExampleScreen> get copyWith => - __$$_ExampleScreenCopyWithImpl<_$_ExampleScreen>(this, _$identity); + _$$ExampleScreenImplCopyWith<_$ExampleScreenImpl> get copyWith => + __$$ExampleScreenImplCopyWithImpl<_$ExampleScreenImpl>(this, _$identity); @override Map toJson() { - return _$$_ExampleScreenToJson( + return _$$ExampleScreenImplToJson( this, ); } @@ -139,15 +139,15 @@ class _$_ExampleScreen implements _ExampleScreen { abstract class _ExampleScreen implements ExampleScreen { const factory _ExampleScreen({required final String assetPath}) = - _$_ExampleScreen; + _$ExampleScreenImpl; factory _ExampleScreen.fromJson(Map json) = - _$_ExampleScreen.fromJson; + _$ExampleScreenImpl.fromJson; @override String get assetPath; @override @JsonKey(ignore: true) - _$$_ExampleScreenCopyWith<_$_ExampleScreen> get copyWith => + _$$ExampleScreenImplCopyWith<_$ExampleScreenImpl> get copyWith => throw _privateConstructorUsedError; } diff --git a/examples/mirai_gallery/lib/app/example/example_screen.g.dart b/examples/mirai_gallery/lib/app/example/example_screen.g.dart index e05d6bc5..49fa1de9 100644 --- a/examples/mirai_gallery/lib/app/example/example_screen.g.dart +++ b/examples/mirai_gallery/lib/app/example/example_screen.g.dart @@ -6,12 +6,12 @@ part of 'example_screen.dart'; // JsonSerializableGenerator // ************************************************************************** -_$_ExampleScreen _$$_ExampleScreenFromJson(Map json) => - _$_ExampleScreen( +_$ExampleScreenImpl _$$ExampleScreenImplFromJson(Map json) => + _$ExampleScreenImpl( assetPath: json['assetPath'] as String, ); -Map _$$_ExampleScreenToJson(_$_ExampleScreen instance) => +Map _$$ExampleScreenImplToJson(_$ExampleScreenImpl instance) => { 'assetPath': instance.assetPath, }; diff --git a/examples/mirai_gallery/pubspec.lock b/examples/mirai_gallery/pubspec.lock index 7546ae9b..560c5802 100644 --- a/examples/mirai_gallery/pubspec.lock +++ b/examples/mirai_gallery/pubspec.lock @@ -77,10 +77,10 @@ packages: dependency: transitive description: name: build_resolvers - sha256: d912852cce27c9e80a93603db721c267716894462e7033165178b91138587972 + sha256: "64e12b0521812d1684b1917bc80945625391cb9bdd4312536b1d69dcb6133ed8" url: "https://pub.dev" source: hosted - version: "2.3.2" + version: "2.4.1" build_runner: dependency: "direct dev" description: @@ -93,10 +93,10 @@ packages: dependency: transitive description: name: build_runner_core - sha256: "6d6ee4276b1c5f34f21fdf39425202712d2be82019983d52f351c94aafbc2c41" + sha256: c9e32d21dd6626b5c163d48b037ce906bbe428bc23ab77bcd77bb21e593b6185 url: "https://pub.dev" source: hosted - version: "7.2.10" + version: "7.2.11" built_collection: dependency: transitive description: @@ -109,10 +109,10 @@ packages: dependency: transitive description: name: built_value - sha256: ff627b645b28fb8bdb69e645f910c2458fd6b65f6585c3a53e0626024897dedf + sha256: a8de5955205b4d1dbbbc267daddf2178bd737e4bab8987c04a500478c9651e74 url: "https://pub.dev" source: hosted - version: "8.6.2" + version: "8.6.3" characters: dependency: transitive description: @@ -141,10 +141,10 @@ packages: dependency: transitive description: name: code_builder - sha256: "315a598c7fbe77f22de1c9da7cfd6fd21816312f16ffa124453b4fc679e540f1" + sha256: "1be9be30396d7e4c0db42c35ea6ccd7cc6a1e19916b5dc64d6ac216b5544d677" url: "https://pub.dev" source: hosted - version: "4.6.0" + version: "4.7.0" collection: dependency: transitive description: @@ -181,18 +181,18 @@ packages: dependency: transitive description: name: dart_style - sha256: "1efa911ca7086affd35f463ca2fc1799584fb6aa89883cf0af8e3664d6a02d55" + sha256: abd7625e16f51f554ea244d090292945ec4d4be7bfbaf2ec8cccea568919d334 url: "https://pub.dev" source: hosted - version: "2.3.2" + version: "2.3.3" dio: dependency: "direct main" description: name: dio - sha256: ce75a1b40947fea0a0e16ce73337122a86762e38b982e1ccb909daa3b9bc4197 + sha256: "417e2a6f9d83ab396ec38ff4ea5da6c254da71e4db765ad737a42af6930140b7" url: "https://pub.dev" source: hosted - version: "5.3.2" + version: "5.3.3" fake_async: dependency: transitive description: @@ -247,10 +247,10 @@ packages: dependency: "direct dev" description: name: freezed - sha256: "83462cfc33dc9680533a7f3a4a6ab60aa94f287db5f4ee6511248c22833c497f" + sha256: "21bf2825311de65501d22e563e3d7605dff57fb5e6da982db785ae5372ff018a" url: "https://pub.dev" source: hosted - version: "2.4.2" + version: "2.4.5" freezed_annotation: dependency: "direct main" description: @@ -390,26 +390,23 @@ packages: mirai: dependency: "direct main" description: - name: mirai - sha256: "7c14ce9731f2779f517735402127c03631e7243427e672ea620101ae8e0f1fb4" - url: "https://pub.dev" - source: hosted + path: "../../packages/mirai" + relative: true + source: path version: "0.5.1" mirai_framework: - dependency: transitive + dependency: "direct overridden" description: - name: mirai_framework - sha256: a8fcd5cb782bb054587d7cddcbc688f5f9392017ac0a43f8df6a11872bee98db - url: "https://pub.dev" - source: hosted + path: "../../packages/mirai_framework" + relative: true + source: path version: "0.0.2" mirai_webview: dependency: "direct main" description: - name: mirai_webview - sha256: baf0048263357e1b69e2caa19d43823c96946628443b4f41ae6f5737452cb7dc - url: "https://pub.dev" - source: hosted + path: "../../packages/mirai_webview" + relative: true + source: path version: "0.0.2" nested: dependency: transitive @@ -620,18 +617,18 @@ packages: dependency: transitive description: name: webview_flutter - sha256: "82f6787d5df55907aa01e49bd9644f4ed1cc82af7a8257dd9947815959d2e755" + sha256: c1ab9b81090705c6069197d9fdc1625e587b52b8d70cdde2339d177ad0dbb98e url: "https://pub.dev" source: hosted - version: "4.2.4" + version: "4.4.1" webview_flutter_android: dependency: transitive description: name: webview_flutter_android - sha256: "9427774649fd3c8b7ff53523051395d13aed2ca355822b822e6493d79f5fc05a" + sha256: b0cd33dd7d3dd8e5f664e11a19e17ba12c352647269921a3b568406b001f1dff url: "https://pub.dev" source: hosted - version: "3.10.0" + version: "3.12.0" webview_flutter_platform_interface: dependency: transitive description: @@ -644,10 +641,10 @@ packages: dependency: transitive description: name: webview_flutter_wkwebview - sha256: d2f7241849582da80b79acb03bb936422412ce5c0c79fb5f6a1de5421a5aecc4 + sha256: b4b42295b3aa91ed22ba6d3dd7de56efbb8f3ab3d6e41d8b1615d13537c7801d url: "https://pub.dev" source: hosted - version: "3.7.4" + version: "3.9.2" yaml: dependency: transitive description: @@ -657,5 +654,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.1.0 <4.0.0" + dart: ">=3.1.0-185.0.dev <4.0.0" flutter: ">=3.7.0" diff --git a/examples/mirai_gallery/pubspec_overrides.yaml b/examples/mirai_gallery/pubspec_overrides.yaml new file mode 100644 index 00000000..c1d7530b --- /dev/null +++ b/examples/mirai_gallery/pubspec_overrides.yaml @@ -0,0 +1,8 @@ +# melos_managed_dependency_overrides: mirai,mirai_framework,mirai_webview +dependency_overrides: + mirai: + path: ../../packages/mirai + mirai_framework: + path: ../../packages/mirai_framework + mirai_webview: + path: ../../packages/mirai_webview diff --git a/packages/mirai/pubspec_overrides.yaml b/packages/mirai/pubspec_overrides.yaml new file mode 100644 index 00000000..9c1a1d25 --- /dev/null +++ b/packages/mirai/pubspec_overrides.yaml @@ -0,0 +1,4 @@ +# melos_managed_dependency_overrides: mirai_framework +dependency_overrides: + mirai_framework: + path: ../mirai_framework diff --git a/packages/mirai_webview/pubspec_overrides.yaml b/packages/mirai_webview/pubspec_overrides.yaml new file mode 100644 index 00000000..9c1a1d25 --- /dev/null +++ b/packages/mirai_webview/pubspec_overrides.yaml @@ -0,0 +1,4 @@ +# melos_managed_dependency_overrides: mirai_framework +dependency_overrides: + mirai_framework: + path: ../mirai_framework