Skip to content

Commit

Permalink
Merge pull request #209 from Securrency-OSS/asim/mirai-framework-readme
Browse files Browse the repository at this point in the history
Added readme for mirai_framework
  • Loading branch information
divyanshub024 authored Sep 19, 2023
2 parents 342b5b3 + 4b5d97f commit 113c389
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/mirai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,4 @@ Check out the [Mirai Gallery](https://github.com/Securrency-OSS/mirai/tree/main/
[securrency_link]: https://securrency.com
[form_screen]: https://github.com/Securrency-OSS/mirai/blob/main/assets/form_screen_image.png
[divyanshu_github]: https://github.com/divyanshub024
[aasim_github]: https://github.com/iamasimkhan
[aasim_github]: https://github.com/i-asimkhan
100 changes: 99 additions & 1 deletion packages/mirai_framework/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,101 @@
# Mirai Framework

A local package containing Mirai framework files
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.

Here are some examples of how the Mirai Framework package can be used:

- Create a custom parser for a new widget that is not supported by Mirai out of the box.
- Create a custom parser for a widget that has additional functionality, such as the ability to handle user input.
- Create a custom action parser to handle a new type of action, such as sending a message to a remote server.
- Create a custom action parser to handle an existing action in a different way, such as logging the action before it is executed.

## Installation 🚀

First, we need to add Mirai Framework to our pubspec.yaml file.

Install the plugin by running the following command from the project root:

```bash
flutter pub add mirai_framework
```

## Usage

1. Import `mirai_framework.dart` at the top of your parser file.

```dart
import 'package:mirai_framework/mirai_framework.dart';
```

2. Initialize your custom parser for a widget or an action and extend it from `MiraiParser` or `MiraiActionParser` like this.

```dart
// define `MyCustomWidget`
@freezed
class MyCustomWidget with _$MyCustomWidget { ... }
```

a. Let's say we are initializing a widget parser.

```dart
class MiraiWidgetPraser extends MiraiParser<MyCustomWidget> {
...
}
```

b. Let's say we are initializing an action parser.

```dart
class MiraiActionPraser extends MiraiActionParser<dynamic> {
...
}
```

3. Now implement the required methods in your custom parser.

a. Let's say we are building a widget parser.

```dart
class MiraiWidgetParser extends MiraiParser<MyCustomWidget> {
@override
MyCustomWidget getModel(Map<String, dynamic> json) {
// TODO: implement getModel
throw UnimplementedError();
}
@override
Widget parse(BuildContext context, MyCustomWidget model) {
// TODO: implement parse
throw UnimplementedError();
}
@override
// TODO: implement type
String get type => throw UnimplementedError();
}
```

b. Let's say we are building an action parser.

```dart
class MiraiActionPraser extends MiraiActionParser<dynamic> {
@override
// TODO: implement actionType
String get actionType => throw UnimplementedError();
@override
getModel(Map<String, dynamic> json) {
// TODO: implement getModel
throw UnimplementedError();
}
@override
FutureOr onCall(BuildContext context, model) {
// TODO: implement onCall
throw UnimplementedError();
}
}
```
80 changes: 80 additions & 0 deletions packages/mirai_framework/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
## Example

1. Import `mirai_framework.dart` at the top of your parser file.

```dart
import 'package:mirai_framework/mirai_framework.dart';
```

2. Initialize your custom parser for a widget or an action and extend it from `MiraiParser` or `MiraiActionParser` like this.

```dart
// define `MyCustomWidget`
@freezed
class MyCustomWidget with _$MyCustomWidget { ... }
```

a. Let's say we are initializing a widget parser.

```dart
class MiraiWidgetPraser extends MiraiParser<MyCustomWidget> {
...
}
```

b. Let's say we are initializing an action parser.

```dart
class MiraiActionPraser extends MiraiActionParser<dynamic> {
...
}
```

3. Now implement the required methods in your custom parser.

a. Let's say we are building a widget parser.

```dart
class MiraiWidgetParser extends MiraiParser<MyCustomWidget> {
@override
MyCustomWidget getModel(Map<String, dynamic> json) {
// TODO: implement getModel
throw UnimplementedError();
}
@override
Widget parse(BuildContext context, MyCustomWidget model) {
// TODO: implement parse
throw UnimplementedError();
}
@override
// TODO: implement type
String get type => throw UnimplementedError();
}
```

b. Let's say we are building an action parser.

```dart
class MiraiActionPraser extends MiraiActionParser<dynamic> {
@override
// TODO: implement actionType
String get actionType => throw UnimplementedError();
@override
getModel(Map<String, dynamic> json) {
// TODO: implement getModel
throw UnimplementedError();
}
@override
FutureOr onCall(BuildContext context, model) {
// TODO: implement onCall
throw UnimplementedError();
}
}
```
1 change: 0 additions & 1 deletion packages/mirai_framework/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: mirai_framework
description: A local package containing Mirai framework files
version: 0.0.1
homepage: https://github.com/Securrency-OSS/mirai
publish_to: none

environment:
sdk: '>=3.1.0 <4.0.0'
Expand Down

0 comments on commit 113c389

Please sign in to comment.