Skip to content

Commit

Permalink
Merge pull request #9 from nylo-core/master
Browse files Browse the repository at this point in the history
v0.6.0 changes
  • Loading branch information
agordn52 authored Feb 18, 2021
2 parents e2ba600 + cdfece0 commit 060e43a
Show file tree
Hide file tree
Showing 24 changed files with 630 additions and 201 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [0.6.0] - 2021-02-18

* Ability to create plugins for Nylo
* Refactored NyRouter class
* Add page transitions
* `StatefulPageWidget` class now has `data()` method
* Controller and model stub update
* new `construct(context)` method for controllers
* Version bump

## [0.5.2] - 2021-01-31

* Fix `onPop` called on null
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<a href="https://github.com/nylo-core/framework"><img alt="GitHub stars" src="https://img.shields.io/github/stars/nylo-core/framework?style=plastic"></a>
</p>

## Nylo Framework (Beta v0.5.2)
## Nylo Framework (Beta v0.6.0)

Nylo is a micro-framework for Flutter which is designed to help simplify app development. Every project provides a simple boilerplate and MVC pattern to help you build apps easier.

Expand Down
16 changes: 8 additions & 8 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,21 @@ packages:
path: ".."
relative: true
source: path
version: "0.5.0"
version: "0.6.0"
package_config:
dependency: transitive
description:
name: package_config
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
page_transition:
dependency: transitive
description:
name: page_transition
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.7+6"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -338,13 +345,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.7+2"
sailor:
dependency: transitive
description:
name: sailor
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.1"
shared_preferences:
dependency: transitive
description:
Expand Down
12 changes: 3 additions & 9 deletions lib/controllers/controller.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:nylo_framework/helpers/helper.dart';
import 'package:queue/queue.dart';
import 'package:sailor/sailor.dart';

/// Class to handle queuing jobs
class BusQueue {
Expand Down Expand Up @@ -38,16 +37,16 @@ abstract class BaseController {
BaseController({this.context, this.request});

dynamic data() => this.request.data();

construct(BuildContext context) async {}
}

/// Base class to handle requests
class NyRequest {
String currentRoute;
NyArgument _args;
ParamMap _params;
NyRequest({this.currentRoute, NyArgument args, ParamMap params}) {
NyRequest({this.currentRoute, NyArgument args}) {
_args = args;
_params = params;
}

/// Write [data] to controller
Expand All @@ -59,9 +58,4 @@ class NyRequest {
dynamic data() {
return _args == null ? null : _args.data;
}

/// Returns a parameter used in the router.dart file for a route
dynamic param(String key) {
return _params.param(key);
}
}
80 changes: 2 additions & 78 deletions lib/helpers/helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:logger/logger.dart';
import 'package:nylo_framework/localization/app_localization.dart';
import 'package:nylo_framework/router/router.dart';
import 'package:sailor/sailor.dart';
import 'package:nylo_framework/router/models/base_arguments.dart';

/// Returns a value from the .env file
/// the [key] must exist as a string value e.g. APP_NAME.
Expand Down Expand Up @@ -245,81 +244,6 @@ class NyArgument extends BaseArguments {
NyArgument(this.data);
}

/// Helper class for navigation
class NyNav {
NyNav.to({
@required String routeName,
dynamic data,
NavigationType navigationType = NavigationType.push,
dynamic result,
bool Function(Route<dynamic> route) removeUntilPredicate,
List<SailorTransition> transitions,
Duration transitionDuration,
Curve transitionCurve,
Map<String, dynamic> params,
CustomSailorTransition customTransition,
}) {
NyArgument nyArgument = NyArgument(data);
NyNavigator.instance.router.navigate(
routeName,
args: nyArgument,
navigationType: navigationType,
result: result,
removeUntilPredicate: removeUntilPredicate,
transitions: transitions,
transitionDuration: transitionDuration,
transitionCurve: transitionCurve,
params: params,
customTransition: customTransition,
);
}
}

NavigationType navigationType(NavType navType) {
if (navType == NavType.push) {
return NavigationType.push;
}
if (navType == NavType.pushReplace) {
return NavigationType.pushReplace;
}
if (navType == NavType.pushAndRemoveUntil) {
return NavigationType.pushAndRemoveUntil;
}
if (navType == NavType.popAndPushNamed) {
return NavigationType.popAndPushNamed;
}
return null;
}

enum NavType { push, pushReplace, pushAndRemoveUntil, popAndPushNamed }

List<SailorTransition> routeTransitions(
void Function(List<RouteTransition> list) transition) {
List<RouteTransition> transitions = [];
transition(transitions);
List<SailorTransition> tmp = [];

if (transitions.contains(RouteTransition.fade_in)) {
tmp.add(SailorTransition.fade_in);
}
if (transitions.contains(RouteTransition.slide_from_right)) {
tmp.add(SailorTransition.slide_from_right);
}
if (transitions.contains(RouteTransition.slide_from_left)) {
tmp.add(SailorTransition.slide_from_left);
}
if (transitions.contains(RouteTransition.slide_from_top)) {
tmp.add(SailorTransition.slide_from_top);
}
if (transitions.contains(RouteTransition.slide_from_bottom)) {
tmp.add(SailorTransition.slide_from_bottom);
}
if (transitions.contains(RouteTransition.zoom_in)) {
tmp.add(SailorTransition.zoom_in);
}
return tmp;
}

/// Logger used for messages you want to print to the console.
class NyLogger {
Logger _logger = Logger(
Expand Down Expand Up @@ -353,4 +277,4 @@ String trans(BuildContext context, String key) =>
AppLocalizations.of(context).trans(key);

/// Nylo version
const String nyloVersion = 'v0.5-beta.0';
const String nyloVersion = 'v0.6-beta.0';
6 changes: 5 additions & 1 deletion lib/metro/stubs/controller_stub.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
String controllerStub({String controllerName}) => '''
import 'controller.dart';
import 'package:flutter/widgets.dart';
class ${controllerName}Controller extends Controller {
${controllerName}Controller();
@override
construct(BuildContext context) {
}
}
''';
7 changes: 3 additions & 4 deletions lib/metro/stubs/model_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ ${isStorable == true ? "import 'package:nylo_framework/helpers/helper.dart';\n\n
${isStorable == true ? '''
@override
toStorage() => {
// 'my_data_key': this.myVal
};
@override
fromStorage(dynamic data) {
// this.myVal = data['my_data_key'];
}
''' : ""}
}
''' : ""}}
''';
13 changes: 13 additions & 0 deletions lib/nylo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter/material.dart';
import 'package:nylo_framework/plugin/nylo_plugin.dart';
import 'package:nylo_framework/router/router.dart';

class Nylo {
NyRouter router;
ThemeData themeData;
Nylo({this.router, this.themeData});

use(NyPlugin plugin) {
plugin.initPackage(this);
}
}
5 changes: 4 additions & 1 deletion lib/nylo_framework.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:nylo_framework/controllers/controller.dart';
import 'package:nylo_framework/helpers/helper.dart';
import 'package:nylo_framework/nylo.dart';
import 'package:nylo_framework/router/router.dart';
import 'package:nylo_framework/theme/helper/theme_helper.dart';
import 'package:queue/queue.dart';

/// Run to init classes used in Nylo
Future initNylo({@required ThemeData theme}) async {
Future initNylo({@required ThemeData theme, @required NyRouter router}) async {
await DotEnv().load('.env');
if (theme != null) {
CurrentTheme.instance.theme = theme;
Expand All @@ -17,4 +19,5 @@ Future initNylo({@required ThemeData theme}) async {
delay: Duration(milliseconds: getEnv("QUEUE_DELAY", defaultValue: 10)),
parallel: getEnv("QUEUE_PARALLEL", defaultValue: 1),
);
return Nylo(router: router, themeData: theme);
}
11 changes: 11 additions & 0 deletions lib/plugin/nylo_plugin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:nylo_framework/nylo.dart';

class NyPlugin {
Nylo nyloApp;
initPackage(Nylo nylo) {
nyloApp = nylo;
this.construct();
}

construct() {}
}
15 changes: 15 additions & 0 deletions lib/router/errors/route_not_found.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:meta/meta.dart';

class RouteNotFoundError extends Error {
final String name;

RouteNotFoundError({
@required this.name,
});

@override
String toString() {
return "** Route '$name' not found! Make sure you are not using the wrong name"
" or have registered the route.";
}
}
25 changes: 25 additions & 0 deletions lib/router/models/arguments_wrapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:nylo_framework/router/models/base_arguments.dart';
import 'package:page_transition/page_transition.dart';

class ArgumentsWrapper {
BaseArguments baseArguments;
PageTransitionType pageTransitionType;
Duration transitionDuration;

ArgumentsWrapper(
{this.baseArguments, this.transitionDuration, this.pageTransitionType});

ArgumentsWrapper copyWith(
{BaseArguments baseArguments, PageTransitionType pageTransitionType}) {
return ArgumentsWrapper(
baseArguments: baseArguments ?? this.baseArguments,
transitionDuration: transitionDuration ?? this.transitionDuration,
pageTransitionType: pageTransitionType ?? this.pageTransitionType);
}

@override
String toString() {
return 'ArgumentsWrapper{baseArguments: $baseArguments, '
'transitionDuration: $transitionDuration, ';
}
}
1 change: 1 addition & 0 deletions lib/router/models/base_arguments.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abstract class BaseArguments {}
6 changes: 6 additions & 0 deletions lib/router/models/ny_argument.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:nylo_framework/router/models/base_arguments.dart';

class NyArgument extends BaseArguments {
dynamic data;
NyArgument(this.data);
}
32 changes: 32 additions & 0 deletions lib/router/models/nyrouter_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:nylo_framework/router/ui/page_not_found.dart';

/// Options to configure a Nylo Router instance.
class NyRouterOptions {
final bool handleNameNotFoundUI;
final Widget notFoundPage;
final Duration transitionDuration;

/// Should display logs in console. Nylo Router prints some useful logs
/// which can be helpful during development.
///
/// By default logs are disabled i.e. value is set to [false].
final bool isLoggingEnabled;

/// A navigator key lets NyRouter grab the [NavigatorState] from a [MaterialApp]
/// or a [CupertinoApp]. All navigation operations (push, pop, etc) are carried
/// out using this [NavigatorState].
///
/// This is the same [NavigatorState] that is returned by [Navigator.of(context)]
/// (when there is only a single [Navigator] in Widget tree, i.e. from [MaterialApp]
/// or [CupertinoApp]).
final GlobalKey<NavigatorState> navigatorKey;

const NyRouterOptions({
this.notFoundPage = const PageNotFound(),
this.handleNameNotFoundUI = false,
this.isLoggingEnabled = false,
this.transitionDuration = const Duration(milliseconds: 300),
this.navigatorKey,
}) : assert(handleNameNotFoundUI != null);
}
Loading

0 comments on commit 060e43a

Please sign in to comment.