Skip to content

Commit 711fd17

Browse files
authored
Merge pull request #8 from nylo-core/master
v2.2.1 - updates
2 parents d32fa3b + f79c2eb commit 711fd17

File tree

9 files changed

+55
-42
lines changed

9 files changed

+55
-42
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [2.2.1] - 2021-12-10
2+
3+
* Upgrade to Dart 2.15
4+
* Update toast notifications
5+
* Refactor methods in localization
6+
17
## [2.2.0] - 2021-12-07
28

39
* New validator added to NyState. Allows you to validate data in widgets.

lib/alerts/toast_notification.dart

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,43 @@ import 'package:nylo_support/alerts/toast_enums.dart';
55

66
/// ToastNotificationStyleMetaHelper is used to return
77
/// the correct value for the [ToastNotificationStyleType] toast style.
8-
class ToastNotificationStyleMetaHelper {
9-
static ToastMeta getValue(ToastNotificationStyleType style) {
8+
class _ToastNotificationStyleMetaHelper {
9+
static _ToastMeta getValue(ToastNotificationStyleType? style) {
1010
switch (style) {
11+
case null:
1112
case ToastNotificationStyleType.SUCCESS:
12-
return ToastMeta.success(action: () {
13+
return _ToastMeta.success(action: () {
1314
ToastManager().dismissAll(showAnim: true);
1415
});
1516
case ToastNotificationStyleType.WARNING:
16-
return ToastMeta.warning(action: () {
17+
return _ToastMeta.warning(action: () {
1718
ToastManager().dismissAll(showAnim: true);
1819
});
1920
case ToastNotificationStyleType.INFO:
20-
return ToastMeta.info(action: () {
21+
return _ToastMeta.info(action: () {
2122
ToastManager().dismissAll(showAnim: true);
2223
});
2324
case ToastNotificationStyleType.DANGER:
24-
return ToastMeta.danger(action: () {
25+
return _ToastMeta.danger(action: () {
2526
ToastManager().dismissAll(showAnim: true);
2627
});
2728
default:
28-
return ToastMeta.success(action: () {
29+
return _ToastMeta.success(action: () {
2930
ToastManager().dismissAll(showAnim: true);
3031
});
3132
}
3233
}
3334
}
3435

3536
/// Toast Meta makes it easy to use pre-defined styles in the toast alert.
36-
class ToastMeta {
37+
class _ToastMeta {
3738
Widget icon;
3839
String title;
3940
String description;
4041
Color color;
4142
Function? action;
4243
Duration duration;
43-
ToastMeta(
44+
_ToastMeta(
4445
{required this.icon,
4546
required this.title,
4647
required this.description,
@@ -49,7 +50,7 @@ class ToastMeta {
4950
this.duration = const Duration(seconds: 2)});
5051

5152
/// DEFAULT SUCCESS TOAST META
52-
ToastMeta.success(
53+
_ToastMeta.success(
5354
{this.icon = const Icon(Icons.check, color: Colors.white, size: 30),
5455
this.title = "Success",
5556
this.description = "",
@@ -58,7 +59,7 @@ class ToastMeta {
5859
this.duration = const Duration(seconds: 5)});
5960

6061
/// DEFAULT INFO TOAST META
61-
ToastMeta.info(
62+
_ToastMeta.info(
6263
{this.icon = const Icon(Icons.info, color: Colors.white, size: 30),
6364
this.title = "",
6465
this.description = "",
@@ -67,7 +68,7 @@ class ToastMeta {
6768
this.duration = const Duration(seconds: 5)});
6869

6970
/// DEFAULT WARNING TOAST META
70-
ToastMeta.warning(
71+
_ToastMeta.warning(
7172
{this.icon =
7273
const Icon(Icons.error_outline, color: Colors.white, size: 30),
7374
this.title = "Oops!",
@@ -77,7 +78,7 @@ class ToastMeta {
7778
this.duration = const Duration(seconds: 6)});
7879

7980
/// DEFAULT DANGER TOAST META
80-
ToastMeta.danger(
81+
_ToastMeta.danger(
8182
{this.icon = const Icon(Icons.warning, color: Colors.white, size: 30),
8283
this.title = "Oops!",
8384
this.description = "",
@@ -91,12 +92,12 @@ class ToastMeta {
9192
/// i.e [ToastNotificationStyleType.SUCCESS]
9293
/// Set a title, description to personalise the message.
9394
showToastNotification(BuildContext context,
94-
{required ToastNotificationStyleType style,
95+
{ToastNotificationStyleType? style,
9596
String? title,
9697
IconData? icon,
9798
String description = "",
9899
Duration? duration}) {
99-
ToastMeta toastMeta = ToastNotificationStyleMetaHelper.getValue(style);
100+
_ToastMeta toastMeta = _ToastNotificationStyleMetaHelper.getValue(style);
100101
toastMeta.title = toastMeta.title;
101102
if (title != null) {
102103
toastMeta.title = title;

lib/localization/app_localization.dart

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'dart:convert';
44
import 'dart:ui';
55

66
import 'package:flutter/cupertino.dart';
7-
import 'package:flutter/material.dart';
87
import 'package:flutter/services.dart';
98
import 'package:flutter_localizations/flutter_localizations.dart';
109

@@ -77,7 +76,7 @@ class NyLocalization {
7776
// --- locale type --- //
7877
_localeType = localeType ?? LocaleType.device;
7978

80-
// --- language list --- //
79+
// --- language list --- //showToastNotification
8180
_langList = languagesList;
8281

8382
if (languageCode != null) {
@@ -102,14 +101,14 @@ class NyLocalization {
102101

103102
if (_assetsDir != null) {
104103
_assetsDir = assetsDirectory;
105-
_values = await initLanguage(_locale!.languageCode);
104+
_values = await _initLanguage(_locale!.languageCode);
106105
} else {
107106
_values = valuesAsMap;
108107
}
109108
}
110109

111110
/// Loads language Map<key, value>
112-
initLanguage(String languageCode) async {
111+
_initLanguage(String languageCode) async {
113112
String filePath = "$_assetsDir$languageCode.json";
114113
String content = await rootBundle.loadString(filePath);
115114
return json.decode(content);
@@ -122,8 +121,8 @@ class NyLocalization {
122121

123122
String? returnValue = value;
124123

125-
if (isNestedKey(key)) {
126-
returnValue = getNested(key);
124+
if (_isNestedKey(key)) {
125+
returnValue = _getNested(key);
127126
}
128127

129128
if (returnValue == null) {
@@ -138,8 +137,8 @@ class NyLocalization {
138137
return value;
139138
}
140139

141-
String? getNested(String key) {
142-
if (isNestedCached(key)) return _values![key];
140+
String? _getNested(String key) {
141+
if (_isNestedCached(key)) return _values![key];
143142

144143
final keys = key.split('.');
145144
final kHead = keys.first;
@@ -153,23 +152,23 @@ class NyLocalization {
153152
/// If we found the value, cache it. If the value is null then
154153
/// we're not going to cache it, and returning null instead.
155154
if (value != null) {
156-
cacheNestedKey(key, value);
155+
_cacheNestedKey(key, value);
157156
}
158157

159158
return value;
160159
}
161160

162-
bool isNestedCached(String key) => _values!.containsKey(key);
161+
bool _isNestedCached(String key) => _values!.containsKey(key);
163162

164-
void cacheNestedKey(String key, String value) {
165-
if (!isNestedKey(key)) {
163+
void _cacheNestedKey(String key, String value) {
164+
if (!_isNestedKey(key)) {
166165
throw Exception('Cannot cache a key that is not nested.');
167166
}
168167

169168
_values![key] = value;
170169
}
171170

172-
bool isNestedKey(String key) =>
171+
bool _isNestedKey(String key) =>
173172
!_values!.containsKey(key) && key.contains('.');
174173

175174
/// changes active language
@@ -194,6 +193,18 @@ class NyLocalization {
194193
}
195194
}
196195

196+
/// changes locale
197+
Future<void> setLocale({
198+
required Locale locale,
199+
}) async {
200+
_locale = locale;
201+
202+
String filePath = "$_assetsDir${_locale!.languageCode}.json";
203+
String content = await rootBundle.loadString(filePath);
204+
205+
_values = json.decode(content);
206+
}
207+
197208
/// isDirectionRTL(BuildContext context)
198209
/// returns `true` if active language direction is TRL
199210
bool isDirectionRTL(BuildContext context) =>

lib/router/router.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter/widgets.dart';
32
import 'package:nylo_support/helpers/helper.dart';
43
import 'package:nylo_support/router/errors/route_not_found.dart';
54
import 'package:nylo_support/router/models/arguments_wrapper.dart';

lib/router/ui/page_not_found.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter/widgets.dart';
32

43
class PageNotFound extends StatelessWidget {
54
const PageNotFound();

lib/validation/rules.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ class URLRule extends ValidationRule {
106106
/// STRING RULE
107107
class StringRule extends ValidationRule {
108108
StringRule(String attribute)
109-
: super(
110-
signature: "string",
111-
description: "The $attribute is not valid");
109+
: super(signature: "string", description: "The $attribute is not valid");
112110

113111
@override
114112
bool handle(Map<String, dynamic> info) {

lib/widgets/ny_state.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:flutter/material.dart';
2-
import 'package:flutter/widgets.dart';
32
import 'package:nylo_support/alerts/toast_enums.dart';
43
import 'package:nylo_support/alerts/toast_notification.dart';
54
import 'package:nylo_support/exceptions/validation_exception.dart';

pubspec.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ packages:
1414
name: async
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "2.8.1"
17+
version: "2.8.2"
1818
boolean_selector:
1919
dependency: transitive
2020
description:
@@ -28,7 +28,7 @@ packages:
2828
name: characters
2929
url: "https://pub.dartlang.org"
3030
source: hosted
31-
version: "1.1.0"
31+
version: "1.2.0"
3232
charcode:
3333
dependency: transitive
3434
description:
@@ -160,7 +160,7 @@ packages:
160160
name: matcher
161161
url: "https://pub.dartlang.org"
162162
source: hosted
163-
version: "0.12.10"
163+
version: "0.12.11"
164164
meta:
165165
dependency: transitive
166166
description:
@@ -235,7 +235,7 @@ packages:
235235
name: test_api
236236
url: "https://pub.dartlang.org"
237237
source: hosted
238-
version: "0.4.2"
238+
version: "0.4.3"
239239
typed_data:
240240
dependency: transitive
241241
description:
@@ -256,7 +256,7 @@ packages:
256256
name: vector_math
257257
url: "https://pub.dartlang.org"
258258
source: hosted
259-
version: "2.1.0"
259+
version: "2.1.1"
260260
sdks:
261-
dart: ">=2.14.0 <3.0.0"
261+
dart: ">=2.15.0 <3.0.0"
262262
flutter: ">=2.0.0"

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name: nylo_support
22
description: Support library for the Nylo framework. This library supports routing, widgets, localization, cli, storage and more.
3-
version: 2.2.0
3+
version: 2.2.1
44
homepage: https://nylo.dev
55
repository: https://github.com/nylo-core/support
66
issue_tracker: https://github.com/nylo-core/support/issues
77
documentation: https://github.com/nylo-core/support
88

99
environment:
10-
sdk: ">=2.14.0 <3.0.0"
10+
sdk: ">=2.15.0 <3.0.0"
1111
flutter: ">=1.17.0"
1212

1313
dependencies:

0 commit comments

Comments
 (0)