Skip to content

Commit 113c389

Browse files
Merge pull request #209 from Securrency-OSS/asim/mirai-framework-readme
Added readme for mirai_framework
2 parents 342b5b3 + 4b5d97f commit 113c389

File tree

4 files changed

+180
-3
lines changed

4 files changed

+180
-3
lines changed

packages/mirai/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,4 +411,4 @@ Check out the [Mirai Gallery](https://github.com/Securrency-OSS/mirai/tree/main/
411411
[securrency_link]: https://securrency.com
412412
[form_screen]: https://github.com/Securrency-OSS/mirai/blob/main/assets/form_screen_image.png
413413
[divyanshu_github]: https://github.com/divyanshub024
414-
[aasim_github]: https://github.com/iamasimkhan
414+
[aasim_github]: https://github.com/i-asimkhan

packages/mirai_framework/README.md

+99-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,101 @@
11
# Mirai Framework
22

3-
A local package containing Mirai framework files
3+
The Mirai Framework package contains the framework files for (Mirai)[https://github.com/Securrency-OSS/mirai], such as MiraiParser and MiraiActionParser. These classes provide a simple way to create custom parsers for widgets and actions in Mirai. This can be useful for extending the functionality of Mirai or for implementing custom widgets and actions.
4+
5+
Here are some examples of how the Mirai Framework package can be used:
6+
7+
- Create a custom parser for a new widget that is not supported by Mirai out of the box.
8+
- Create a custom parser for a widget that has additional functionality, such as the ability to handle user input.
9+
- Create a custom action parser to handle a new type of action, such as sending a message to a remote server.
10+
- Create a custom action parser to handle an existing action in a different way, such as logging the action before it is executed.
11+
12+
## Installation 🚀
13+
14+
First, we need to add Mirai Framework to our pubspec.yaml file.
15+
16+
Install the plugin by running the following command from the project root:
17+
18+
```bash
19+
flutter pub add mirai_framework
20+
```
21+
22+
## Usage
23+
24+
1. Import `mirai_framework.dart` at the top of your parser file.
25+
26+
```dart
27+
import 'package:mirai_framework/mirai_framework.dart';
28+
```
29+
30+
2. Initialize your custom parser for a widget or an action and extend it from `MiraiParser` or `MiraiActionParser` like this.
31+
32+
```dart
33+
// define `MyCustomWidget`
34+
35+
@freezed
36+
class MyCustomWidget with _$MyCustomWidget { ... }
37+
```
38+
39+
a. Let's say we are initializing a widget parser.
40+
41+
```dart
42+
class MiraiWidgetPraser extends MiraiParser<MyCustomWidget> {
43+
...
44+
}
45+
```
46+
47+
b. Let's say we are initializing an action parser.
48+
49+
```dart
50+
class MiraiActionPraser extends MiraiActionParser<dynamic> {
51+
...
52+
}
53+
```
54+
55+
3. Now implement the required methods in your custom parser.
56+
57+
a. Let's say we are building a widget parser.
58+
59+
```dart
60+
class MiraiWidgetParser extends MiraiParser<MyCustomWidget> {
61+
@override
62+
MyCustomWidget getModel(Map<String, dynamic> json) {
63+
// TODO: implement getModel
64+
throw UnimplementedError();
65+
}
66+
67+
@override
68+
Widget parse(BuildContext context, MyCustomWidget model) {
69+
// TODO: implement parse
70+
throw UnimplementedError();
71+
}
72+
73+
@override
74+
// TODO: implement type
75+
String get type => throw UnimplementedError();
76+
77+
}
78+
79+
```
80+
81+
b. Let's say we are building an action parser.
82+
83+
```dart
84+
class MiraiActionPraser extends MiraiActionParser<dynamic> {
85+
@override
86+
// TODO: implement actionType
87+
String get actionType => throw UnimplementedError();
88+
89+
@override
90+
getModel(Map<String, dynamic> json) {
91+
// TODO: implement getModel
92+
throw UnimplementedError();
93+
}
94+
95+
@override
96+
FutureOr onCall(BuildContext context, model) {
97+
// TODO: implement onCall
98+
throw UnimplementedError();
99+
}
100+
}
101+
```
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
## Example
2+
3+
1. Import `mirai_framework.dart` at the top of your parser file.
4+
5+
```dart
6+
import 'package:mirai_framework/mirai_framework.dart';
7+
```
8+
9+
2. Initialize your custom parser for a widget or an action and extend it from `MiraiParser` or `MiraiActionParser` like this.
10+
11+
```dart
12+
// define `MyCustomWidget`
13+
14+
@freezed
15+
class MyCustomWidget with _$MyCustomWidget { ... }
16+
```
17+
18+
a. Let's say we are initializing a widget parser.
19+
20+
```dart
21+
class MiraiWidgetPraser extends MiraiParser<MyCustomWidget> {
22+
...
23+
}
24+
```
25+
26+
b. Let's say we are initializing an action parser.
27+
28+
```dart
29+
class MiraiActionPraser extends MiraiActionParser<dynamic> {
30+
...
31+
}
32+
```
33+
34+
3. Now implement the required methods in your custom parser.
35+
36+
a. Let's say we are building a widget parser.
37+
38+
```dart
39+
class MiraiWidgetParser extends MiraiParser<MyCustomWidget> {
40+
@override
41+
MyCustomWidget getModel(Map<String, dynamic> json) {
42+
// TODO: implement getModel
43+
throw UnimplementedError();
44+
}
45+
46+
@override
47+
Widget parse(BuildContext context, MyCustomWidget model) {
48+
// TODO: implement parse
49+
throw UnimplementedError();
50+
}
51+
52+
@override
53+
// TODO: implement type
54+
String get type => throw UnimplementedError();
55+
56+
}
57+
58+
```
59+
60+
b. Let's say we are building an action parser.
61+
62+
```dart
63+
class MiraiActionPraser extends MiraiActionParser<dynamic> {
64+
@override
65+
// TODO: implement actionType
66+
String get actionType => throw UnimplementedError();
67+
68+
@override
69+
getModel(Map<String, dynamic> json) {
70+
// TODO: implement getModel
71+
throw UnimplementedError();
72+
}
73+
74+
@override
75+
FutureOr onCall(BuildContext context, model) {
76+
// TODO: implement onCall
77+
throw UnimplementedError();
78+
}
79+
}
80+
```

packages/mirai_framework/pubspec.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: mirai_framework
22
description: A local package containing Mirai framework files
33
version: 0.0.1
44
homepage: https://github.com/Securrency-OSS/mirai
5-
publish_to: none
65

76
environment:
87
sdk: '>=3.1.0 <4.0.0'

0 commit comments

Comments
 (0)