|
1 | 1 | # Mirai Framework
|
2 | 2 |
|
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 | + ``` |
0 commit comments