FairCommonPluginMixin mixin

Here is a demo for FairCommonPlugin.

The plugin name must be 'FairCommonPlugin'

class FairCommonPlugin extends IFairPlugin with FairHttpPlugin, FairPermissionPlugin { factory FairCommonPlugin() => fairCommonPlugin; FairCommonPlugin.(); static final FairCommonPlugin fairCommonPlugin = FairCommonPlugin.(); @override Map<String, Function> getRegisterMethods() { return <String, Function>{ 'http': http, 'requestPermission': requestPermission, }; } }

You only need to focus on the implementation of the specific business logic. you can define method in FairCommonPlugin directly or define mixins to implements it. mixins will make business logic more clearly.

mixin FairHttpPlugin implements FairCommonPluginMixin { Future

mixin FairPermissionPlugin implements FairCommonPluginMixin { Future

then add following into your plugin js

// The plugin name must be 'FairCommonPlugin'

let FairCommonPlugin = function () { return { // The same method name in FairCommonPlugin http: function (resp) { // The same method name in FairCommonPlugin fairCommonPluginRequest(resp, 'http'); }, requestPermission: function (resp) { fairCommonPluginRequest(resp, 'requestPermission'); }, } }

Define it at runApplication

FairApp.runApplication( FairApp(child: MaterialApp()), plugins: <String, IFairPlugin>{ 'FairCommonPlugin': FairCommonPlugin(), }, );

Finally, use it like this:

FairCommonPlugin().http({ // required 'pageName': 'YourPageName', // if need, add a callback 'callback': (dynamic result) { // result is map or null }, // other parameters base on your case 'method': 'GET', });

When you want to add a new business logic, you only need to add a new method in your plugin js and add new method for FairCommonPlugin.

Mixin Applications

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
request(dynamic map, Future<Map?> run(Map reqData)) Future
common request method
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited