Skip to content

Commit

Permalink
Merge pull request #21 from fahamutech/update_update_nulsafe_and_beau…
Browse files Browse the repository at this point in the history
…tify

update to null safe code and beautify code to make it more readable
  • Loading branch information
joshuamshana authored Aug 1, 2022
2 parents 5cc5c31 + 4612731 commit 6abd61b
Show file tree
Hide file tree
Showing 31 changed files with 570 additions and 533 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#

## [1.3.0]
1. Update to null-safe code
2. Improve code readability
3. remove BFastUI helper class and access code directly

## [1.2.0]

Update `flutter_modular` package to 4.3.0
Expand Down
17 changes: 13 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
Copyright 2020 FahamuTech
OpenCodes SmartStock Company Limited.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
184 changes: 107 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# BFastUI - Introduction

State and architecture management library for flutter
State and UI architecture library for flutter inspired
by [flutter_modular](https://modular.flutterando.com.br/docs/flutter_modular/start)
for architecture and ChangeNotifier pattern for states.

![BFast UI](bfastui.png)


## Installation

Open your project's `pubspec.yaml` and add `bfastui` as a dependency:
Expand All @@ -26,85 +27,74 @@ dependencies:
## Module
You organised your domain in your application in modules. Module is a top level abstraction of your
application.
application.
### MainModule
This is the bootstrap module for your application.
Is only defined once your application.
You will required to implement `initRoutes` and `initStates` method
This is the bootstrap module for your application. Is only defined once in your application. You
will required to implement `initRoutes` and `initStates` method

* initRoutes - You will add all routes of the pages your module will use

* initStates - You will add all states you will use in your module


```dart
class MyApp extends MainModuleAdapter{
class MyApp extends MainModuleAdapter {
@override
void initRoutes(String moduleName) {
// TODO: implement initRoutes
}
@override
void initStates(String moduleName) {
// TODO: implement initStates
}
List<RouterAdapter> initRoutes(String moduleName) => [];
@override
List<StateAdapter> initStates(String moduleName) => [];
}
```

### ChildModule

This is the feature module to enclose your specific business logic. Your will required to impelement the following methods
This is the feature module to enclose your specific business logic. Your will required to implement
the following methods.

* initRoutes - You will add all routes of the pages your module will use

* initStates - You will add all states you will use in your module

* moduleName - This will return your module name, name can be any `String` of your choice


```dart
class MyApp extends ChildModuleAdapter{
class ProfileModule extends ChildModuleAdapter {
@override
void initRoutes(String moduleName) {
// TODO: implement initRoutes
}
@override
void initStates(String moduleName) {
// TODO: implement initStates
}
List<RouterAdapter> initRoutes(String moduleName) => [];
@override
String moduleName() {
// TODO: implement moduleName
return 'your-module-name';
}
List<StateAdapter> initStates(String moduleName) => [];
@override
String moduleName() => 'profile-module';
}
```


## Page

Page is what your see presented by your mobile phone. i.e login page. Page belongs to a specific module and characterised with `url` to navigate to. Page can have one or more components which make the whole page functional. To create a page you extend `BFastUIPage` and you will required to implement `build` method which return a `Widget` represent that page.
Page is what your see presented by your mobile phone. i.e login page. Page belongs to a specific
module and characterised with `url` to navigate to. Page can have one or more components which make
the whole page functional. To create a page you extend `PageAdapter` and you will required to
implement `build` method which return a `Widget` represent that page.

* build(var args) - your must provide implementation for this method. `args` parameter your will use it to extract information of that page i.e url parameters. `args` has the following properties
* build(var args) - your must provide implementation for this method. `args` has the following properties

```dart
final Map<String, dynamic> params;
final dynamic data;
final Map<String, dynamic> queryParams;
final dynamic data;
```


```dart
class MyPage extends PageAdapter{
class MyPage extends PageAdapter {
@override
Widget build(var args) {
// TODO: implement build
Expand All @@ -116,32 +106,54 @@ class MyPage extends PageAdapter{

## State

State call information of the current view of your page ( s ).
State is a `ChangeNotifier` class to be used with provider state management under the hood.
State call information of the current view of your page ( s ). State is a `ChangeNotifier` class to
be used with provider state management under the hood.

```dart
class MyState extends StateAdapter{
class MyState extends StateAdapter {
}
```

to notify listerner for changes your will just call `notifyListeners()`
as you would in `ChangeNotifier` class.

## Route
as you would in `ChangeNotifier` class. You can use a state with `active widget` either consumer or selector.
We provider factor method to produce either consumer widget or selector component.

A Route carry information of where to navigate to in your application and whether
to allow someone access or not. You can navigate to another Page or Module.
```dart
class MyHomePage extends PageAdapter {
@override
Widget build(args) {
return Scaffold(
body: Container(
color: Colors.red,
child: Column(
children: [
consumerComponent<MyState>(
builder: (context, state) => Text('${state.count}'),
),
selectorComponent<MyState, int>(
selector: (state) => state.count,
builder: (c, data) => Text('$data'),
)
],
),
),
);
}
}
```

## Route

A Route carry information of where to navigate to in your application and whether to allow someone
access or not. You can navigate to another Page or Module.

### Route Guard

To create a route guard

```dart
class MyRouteAuthGuard extends RouterGuardAdapter{
class MyRouteAuthGuard extends RouterGuardAdapter {
@override
Future<bool> canActivate(String url) {
// TODO: implement canActivate
Expand All @@ -150,64 +162,82 @@ class MyRouteAuthGuard extends RouterGuardAdapter{
}
```

when `canActivate` resolve to `true` the page or a module someone navigate to
will be activated otherwise will return to previous route if available
when `canActivate` resolve to `true` the page or a module someone navigate to will be activated
otherwise will return to previous route if available


## Example
## Complete Application Example

```dart
class MyHomePage extends PageAdapter{
import 'package:bfastui/adapters/main_module.dart';
import 'package:bfastui/adapters/page.dart';
import 'package:bfastui/adapters/router.dart';
import 'package:bfastui/adapters/state.dart';
import 'package:bfastui/controllers/component.dart';
import 'package:bfastui/controllers/module.dart';
import 'package:flutter/material.dart';
class MyHomePage extends PageAdapter {
@override
Widget build(args) {
return Scaffold(
body: Container(
color: Colors.red,
child: Column(
children: [
consumerComponent<MyState>(
builder: (c, state) => Text('${state?.count}'),
),
selectorComponent<MyState, int>(
selector: (s) => s?.count ?? 0,
builder: (c, data) => Text('$data'),
)
],
),
),
);
}
}
class MyState extends StateAdapter{
class MyState extends StateAdapter {
int count = 0;
increase(){
increase() {
count += 1;
notifyListeners();
}
decrement(){
decrement() {
count -= 1;
notifyListeners();
}
@override
void onDispose() {}
}
class MyAppModule extends MainModuleAdapter{
class MyAppModule extends MainModuleAdapter {
@override
void initRoutes(String moduleName) {
BFastUI.navigation(moduleName: moduleName)
.addRoute(RouterAdapter('/home', page: (content,args)=>MyHomePage()));
}
@override
void initStates(String moduleName) {
BFastUI
.states(moduleName: moduleName)
.addState((i) => MyState());
}
List<RouterAdapter> initRoutes(String moduleName) => [
RouterAdapter('/home', page: (c, _) => MyHomePage()),
];
@override
List<StateAdapter> initStates(String moduleName) => [
MyState(),
];
}
void main(){
void main() {
runApp(
BFastUI.module(module: MyAppModule(), component: MaterialApp(
initialPath: '/home'
)).start()
bfastUiApp(
module: MyAppModule(),
component: MaterialApp(
initialRoute: '/home',
),
),
);
}
```

43 changes: 0 additions & 43 deletions lib/adapters/child-module.adapter.dart

This file was deleted.

Loading

0 comments on commit 6abd61b

Please sign in to comment.