Coder Social home page Coder Social logo

securrency-oss / mirai Goto Github PK

View Code? Open in Web Editor NEW
500.0 13.0 61.0 11.99 MB

Mirai is a Server-Driven UI (SDUI) library for Flutter. Mirai allows you to build beautiful cross-platform applications with JSON in real time.

Home Page: https://pub.dev/packages/mirai

License: MIT License

Dart 100.00%
dart flutter sdui server-driven-ui mirai backend-driven-ui json dynamic-ui

mirai's Introduction

Mirai

pub package License: MIT


Mirai is a Server-Driven UI (SDUI) library for Flutter. Mirai allows you to build beautiful cross-platform applications with JSON in real time.

Developed with ๐Ÿ’™ by Securrency

Installation ๐Ÿš€

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

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

flutter pub add mirai

Usage ๐Ÿง‘โ€๐Ÿ’ป

Now that we have successfully installed Mirai, we can import Mirai in main.dart.

import 'package:mirai/mirai.dart';

Next, within main function initialize Mirai.

void main() async {
  await Mirai.initialize();

  runApp(const MyApp());
}

You can also specify your custom Parsers in Mirai.initialize and Dio instance.

void main() async {
  final dio = Dio();

  await Mirai.initialize(
    parsers: const [
      ExampleScreenParser(),
    ],
    dio: dio,
  );

  runApp(const MyApp());
}

Finally, replace your MaterialApp with MiraiApp. And call your json with Mirai.fromJson(json, context).

import 'package:flutter/material.dart';
import 'package:mirai/mirai.dart';

void main() async {
  await Mirai.initialize();

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MiraiApp(
      title: 'Mirai Demo',
      homeBuilder: (context) => Mirai.fromJson(json, context),
    );
  }
}

Example

Here is an example of a basic form screen build with Mirai.

Server

{
  "type": "scaffold",
  "appBar": {
    "type": "appBar",
    "title": {
      "type": "text",
      "data": "Text Field",
      "style": {
        "color": "#ffffff",
        "fontSize": 21
      }
    },
    "backgroundColor": "#4D00E9"
  },
  "backgroundColor": "#ffffff",
  "body": {
    "type": "singleChildScrollView",
    "child": {
      "type": "container",
      "padding": {
        "left": 12,
        "right": 12,
        "top": 12,
        "bottom": 12
      },
      "child": {
        "type": "column",
        "mainAxisAlignment": "center",
        "crossAxisAlignment": "center",
        "children": [
          {
            "type": "sizedBox",
            "height": 24
          },
          {
            "type": "textField",
            "maxLines": 1,
            "keyboardType": "text",
            "textInputAction": "done",
            "textAlign": "start",
            "textCapitalization": "none",
            "textDirection": "ltr",
            "textAlignVertical": "top",
            "obscureText": false,
            "cursorColor": "#FC3F1B",
            "style": {
              "color": "#000000"
            },
            "decoration": {
              "hintText": "What do people call you?",
              "filled": true,
              "icon": {
                "type": "icon",
                "iconType": "cupertino",
                "icon": "person_solid",
                "size": 24
              },
              "hintStyle": {
                "color": "#797979"
              },
              "labelText": "Name*",
              "fillColor": "#F2F2F2"
            },
            "readOnly": false,
            "enabled": true
          },
          {
            "type": "sizedBox",
            "height": 24
          },
          {
            "type": "textField",
            "maxLines": 1,
            "keyboardType": "text",
            "textInputAction": "done",
            "textAlign": "start",
            "textCapitalization": "none",
            "textDirection": "ltr",
            "textAlignVertical": "top",
            "obscureText": false,
            "cursorColor": "#FC3F1B",
            "style": {
              "color": "#000000"
            },
            "decoration": {
              "hintText": "Where can we reach you?",
              "filled": true,
              "icon": {
                "type": "icon",
                "iconType": "cupertino",
                "icon": "phone_solid",
                "size": 24
              },
              "hintStyle": {
                "color": "#797979"
              },
              "labelText": "Phone number*",
              "fillColor": "#F2F2F2"
            },
            "readOnly": false,
            "enabled": true
          },
          {
            "type": "sizedBox",
            "height": 24
          },
          {
            "type": "textField",
            "maxLines": 1,
            "keyboardType": "text",
            "textInputAction": "done",
            "textAlign": "start",
            "textCapitalization": "none",
            "textDirection": "ltr",
            "textAlignVertical": "top",
            "obscureText": false,
            "cursorColor": "#FC3F1B",
            "style": {
              "color": "#000000"
            },
            "decoration": {
              "hintText": "Your email address",
              "filled": true,
              "icon": {
                "type": "icon",
                "iconType": "material",
                "icon": "email",
                "size": 24
              },
              "hintStyle": {
                "color": "#797979"
              },
              "labelText": "Email",
              "fillColor": "#F2F2F2"
            },
            "readOnly": false,
            "enabled": true
          },
          {
            "type": "sizedBox",
            "height": 24
          },
          {
            "type": "sizedBox",
            "height": 100,
            "child": {
              "type": "textField",
              "expands": true,
              "cursorColor": "#FC3F1B",
              "style": {
                "color": "#000000"
              },
              "decoration": {
                "filled": true,
                "hintStyle": {
                  "color": "#797979"
                },
                "labelText": "Life story",
                "fillColor": "#F2F2F2"
              },
              "readOnly": false,
              "enabled": true
            }
          },
          {
            "type": "sizedBox",
            "height": 24
          },
          {
            "type": "textField",
            "maxLines": 1,
            "keyboardType": "text",
            "textInputAction": "done",
            "textAlign": "start",
            "textCapitalization": "none",
            "textDirection": "ltr",
            "textAlignVertical": "top",
            "obscureText": true,
            "cursorColor": "#FC3F1B",
            "style": {
              "color": "#000000"
            },
            "decoration": {
              "filled": true,
              "suffixIcon": {
                "type": "icon",
                "iconType": "cupertino",
                "icon": "eye",
                "size": 24
              },
              "hintStyle": {
                "color": "#797979"
              },
              "labelText": "Password*",
              "fillColor": "#F2F2F2"
            },
            "readOnly": false,
            "enabled": true
          },
          {
            "type": "sizedBox",
            "height": 24
          },
          {
            "type": "textField",
            "maxLines": 1,
            "keyboardType": "text",
            "textInputAction": "done",
            "textAlign": "start",
            "textCapitalization": "none",
            "textDirection": "ltr",
            "textAlignVertical": "top",
            "obscureText": true,
            "cursorColor": "#FC3F1B",
            "style": {
              "color": "#000000"
            },
            "decoration": {
              "filled": true,
              "suffixIcon": {
                "type": "icon",
                "iconType": "cupertino",
                "icon": "eye",
                "size": 24
              },
              "hintStyle": {
                "color": "#797979"
              },
              "labelText": "Re-type password*",
              "fillColor": "#F2F2F2"
            },
            "readOnly": false,
            "enabled": true
          },
          {
            "type": "sizedBox",
            "height": 48
          },
          {
            "type": "elevatedButton",
            "child": {
              "type": "text",
              "data": "Submit"
            },
            "style": {
              "backgroundColor": "#4D00E9",
              "padding": {
                "top": 8,
                "left": 12,
                "right": 12,
                "bottom": 8
              }
            },
            "onPressed": {}
          }
        ]
      }
    }
  }
}

Flutter

import 'package:flutter/material.dart';
import 'package:mirai/mirai.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MiraiApp(
      title: 'Mirai Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Mirai.fromNetwork(
        MiraiRequest(
          url: _url,
          method: Method.get,
        ),
      ),
    );
  }
}

Note:

Mirai provides multiple methods to parse JSONs into Flutter widgets. You can use Mirai.fromNetwork(), Mirai.fromJson() & Mirai.fromAsset()

That's it with just few lines of code your SDUI app is up and running.

Form Screen

More examples

Check out the Mirai Gallery app for more such examples.

Contributors โœจ

Maintainers


mirai's People

Contributors

asimkhansecurrency avatar codersangam avatar cscoderr avatar dandoney avatar divyanshub024 avatar divyanshubhargavasecurrency avatar i-asimkhan avatar iampranabray avatar kushalmahapatro avatar loud-at-heart avatar rodolfosilva avatar superiorsd10 avatar tirth-multipl avatar vinothvino42 avatar vkmaxcooldude avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mirai's Issues

feat: Add support for `textButtonTheme` in `MiraiTheme`

Description

Recently we have provided the ThemeData support through our own customized MiraiTheme. Now furthermore, we need to provide support for theme components.

For instance, the text button component theme will look like this.

{
   'textButtonTheme' : {
        'color' : '#ffffff'
    }
}

feat: Add support for `buttonTheme` in `MiraiTheme`

Description

Recently we have provided the ThemeData support through our own customized MiraiTheme. Now furthermore, we need to provide support for theme components.

For instance, the text button component theme will look like this.

{
   'buttonTheme' : {
      ...
   }
}

feat: Add support for `fontFamily` in `MiraiTheme`

Description

We need to provide support for custom fontFamily in the MiraiTheme.

Requirements

  • Allow set fontFamily
  • Allow set fontFamilyFallback

Additional Context

Maybe we could use Google Font to archive that or use fonts placed in the asset folder.
Also we should provide a way to define the fontFamilyFallback.

{
   'fontFamily' : 'Inter',
   'fontFamilyFallback': ['Roboto']
}

feat: Authorization token storage

Description

We need a way to persist and destroy the passkey on the device to allow apps that have authentication to be able to persist the passkey locally and avoid the user having to provide credentials again.
Perhaps a simple encrypted key-value storage will solve this use case.

And also some way to always send this data in the request to the server, through the header perhaps.

Requirements

  • Store the key value provided by the server
  • Destroy the value using the key provided by the server
  • Send the data to the server in every request in the header

Additional Context

This will unlock advanced features when the app needs to keep some data locally to be used in future accesses.

Maybe it's just a feature to store a bearer token locally and send it every time the app requests something from the server.

feat: Add a new Mirai Tab Parser

Description

The goal is to create a MiraiTabParser which will allow users to create the tabs screen & the bottom navigation screen.

Requirements

  • Abiility to pass and customize the tab views and tab items
  • Style the tabs
  • Ability to change the position of tabbar either to top or bottom

fix: App Bar size is fixed in scaffold

Description

In the Scaffold widget, the app bar size is fixed. Any bottom widget added to it is not visible.

Expected Behavior

Appbar should adjust its size according to the bottom widget added to it.

feat: Add support for `floatingActionButtonTheme` in `MiraiTheme`

Description

Recently we have provided the ThemeData support through our own customized MiraiTheme. Now furthermore, we need to provide support for theme components.

For instance, the floating action button component theme will look like this.

{
   'floatingActionButtonTheme' : {
        'color' : '#ffffff'
    }
}

feat: Add support for `elevatedButtonTheme` in `MiraiTheme`

Description

Recently we have provided the ThemeData support through our own customized MiraiTheme. Now furthermore, we need to provide support for theme components.

For instance, the elevated button component theme will look like this.

{
   'elevatedButtonTheme' : {
        'color' : '#ffffff',
         'backgroundColor' : '#4D00E9',
    }
}

feat: Add support for `iconTheme` in `MiraiTheme`

Description

Recently we have provided the ThemeData support through our own customized MiraiTheme. Now furthermore, we need to provide support for theme components.

For instance, the icon component theme will look like this.

{
   'iconTheme' : {
        'size': 24,
        'fill': 1,
    }
}

feat: Add support for `bottomAppBarTheme` in `MiraiTheme`

Description

Recently we have provided the ThemeData support through our own customized MiraiTheme. Now furthermore, we need to provide support for theme components.

For instance, the text button component theme will look like this.

{
   'bottomAppBarTheme' : {
      ...
   }
}

feat: Add support for `outlinedButtonTheme` in `MiraiTheme`

Description

Recently we have provided the ThemeData support through our own customized MiraiTheme. Now furthermore, we need to provide support for theme components.

For instance, the outlined button component theme will look like this.

{
   'outlinedButtonTheme' : {
        'color' : '#ffffff',
         'backgroundColor' : '#4D00E9',
    }
}

feat: Add `BoxDecoration` support in `Mirai` widgets

Description

Currently, we can change the values of widgets in flutter using properties defined in Mirai widget parsers. These properties mostly include size, behaviour, colour and content.

Now we need to provide support for quite powerful property in flutter widgets, which is BoxDecoration and underlying properties of ShapeBorder with borders and shadows and are seriously one of the greatest demands.

feat: Add support for a PushNamed route

Description

Implement support for a pushNamedRoute method, which would allow users to navigate to existing pages without the need to recreate the page in the server. This would make it easier and more efficient for migrate an existent app to Mirai.

Requirements

  • Push to a existent flutter router
  • Push and replace to an existent flutter router
  • Push and remove all previous page to an existent flutter router

feat: Add support for `dialogTheme` in `MiraiTheme`

Description

Recently we have provided the ThemeData support through our own customized MiraiTheme. Now furthermore, we need to provide support for theme components.

For instance, the text button component theme will look like this.

{
   'dialogTheme' : {
      ...
   }
}

feat: Add support for `iconButtonTheme` in `MiraiTheme`

Description

Recently we have provided the ThemeData support through our own customized MiraiTheme. Now furthermore, we need to provide support for theme components.

For instance, the icon button component theme will look like this.

{
   'iconButtonTheme' : {
        'color' : '#ffffff'
    }
}

feat: Add support for `cardTheme` in `MiraiTheme`

Description

Recently we have provided the ThemeData support through our own customized MiraiTheme. Now furthermore, we need to provide support for theme components.

For instance, the text button component theme will look like this.

{
   'cardTheme' : {
      ...
   }
}

feat: Add flutter `Stack` support in `Mirai`

Description
According to official documentation, Stack is a widget that positions its children relative to the edges of its box.

This class is useful if you want to overlap several children in a simple way, for example having some text and an image, overlaid with a gradient and a button attached to the bottom.

Additional Context

For more details please visit the official documentation here

feat: Add support to submit a form

Description

In the LSD library, I've implemented a method to store input values using an InheritedWidget, maintaining all form values in a Map<String, String>. I believe we can incorporate a similar approach in Mirai. Additionally, we can introduce a signal to instruct the UI to disable all input modifications and other related buttons while the form is being submitted. Once the server responds, an Action will be dispatched to inform the UI of any further steps required.

I'm curious if there might be a better approach to achieve this.

Based on your experiences, @divyanshub024 and @i-asimkhan, what do you think is the best way to implement this feature?

Requirements

  • Submit a form
  • Disable fields when form is submitting
  • Disable buttons when the form is submitting
  • Execute a action in the end of the submission request, sented by the server

Additional Context

This issue is complement of: #107, #51

LSD Form Provider:
https://github.com/RodolfoSilva/lsd/blob/main/packages/lsd_form/lib/src/lsd_form_provider.dart

LSD Field Builder:
https://github.com/RodolfoSilva/lsd/blob/main/packages/lsd_form/lib/src/lsd_form_field.dart

LSD Form state
https://github.com/RodolfoSilva/lsd/blob/main/packages/lsd_form/lib/src/lsd_form_data_state.dart

LSD Form widget
https://github.com/RodolfoSilva/lsd/blob/main/packages/lsd_form/lib/src/lsd_form_widget.dart

LSD From Action:
https://github.com/RodolfoSilva/lsd/blob/main/packages/lsd_form/lib/src/lsd_submit_form.dart

feat: Integrate `ThemeData` in Mirai

Background

Currently, we are providing parsers to initialize the app, and these parsers are responsible to parse models provided by users in the back of their app.

return MiraiApp(
     parsers: const [
       ExampleScreenParser(),
     ],
     title: 'Mirai Gallery',
     theme: ThemeData(
       primarySwatch: Colors.blue,
     ),
     home: const HomeScreen(),
);

Description

Just like widget parsers, we should allow users to have parsers for ThemeData so that we can achieve the server-controlled theme for the app.

feat: Add BoxFit Support for Mirai Image

Description

Right now there is no way to set the fit for MiraiImage. We should add the fit property.

The JSON schema should look like this.

'fit': 'cover',

The fit property should take the following values.

  • fill
  • contain
  • cover
  • fitWidth
  • fitHeight
  • none
  • scaleDown

Additional Context

For more details, checkout the BoxFit class

feat: Add support for `bottomSheetTheme` in `MiraiTheme`

Description

Recently we have provided the ThemeData support through our own customized MiraiTheme. Now furthermore, we need to provide support for theme components.

For instance, the text button component theme will look like this.

{
   'bottomSheetTheme' : {
      ...
   }
}

feat: Add support for `bottomNavigationBarTheme` in `MiraiTheme`

Description

Recently we have provided the ThemeData support through our own customized MiraiTheme. Now furthermore, we need to provide support for theme components.

For instance, the text button component theme will look like this.

{
   'bottomNavigationBarTheme' : {
      ...
   }
}

feat: Add support for `appBarTheme` in `MiraiTheme`

Description

Recently we have provided the ThemeData support through our own customized MiraiTheme. Now furthermore, we need to provide support for theme components.

For instance, the app bar component theme will look like this.

{
   'appBarTheme' : {
        'color' : '#ffffff',
         'backgroundColor' : '#4D00E9',
    }
}

docs: Add docs for Mirai Navigation

Description

Add the detailed docs for Mirai Navigation with some examples.

Requirements

  • How to navigate to screens?
  • How to navigate to dialogs?
  • How to navigate to the bottom sheets?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.