1
1
/// Generated by NStack, do not modify this file.
2
2
3
+ import 'package:flutter/foundation.dart' ;
3
4
import 'package:flutter/widgets.dart' ;
4
5
import 'package:nstack/models/language.dart' ;
6
+ import 'package:nstack/models/localize_index.dart' ;
5
7
import 'package:nstack/models/nstack_config.dart' ;
6
8
import 'package:nstack/nstack.dart' ;
7
9
import 'package:nstack/partial/section_key_delegate.dart' ;
@@ -27,21 +29,21 @@ class _DefaultSection extends SectionKeyDelegate {
27
29
class _Test extends SectionKeyDelegate {
28
30
const _Test (): super ('test' );
29
31
30
- String get testDollarSign => get ('testDollarSign' , "\$ testing" );
32
+ String get testDollarSign => get ('testDollarSign' , "\$ testing change back " );
31
33
String get testSingleQuotationMark => get ('testSingleQuotationMark' , "\' testing\' " );
32
34
String get testDoubleQuotationMark => get ('testDoubleQuotationMark' , "\" testing\" " );
33
35
String get testMultipleLines => get ('testMultipleLines' , "testing\n multiple\n lines" );
34
36
}
35
37
36
38
const _config = NStackConfig (projectId: 'h6wJremI2TGFM88gbLkdyljWQuwf2hxhxvCH' , apiKey: 'zp2S18H32b67eYAbRQh94tVw76ZzaKKXlHjd' );
37
39
38
- const _languages = [
39
- Language (id: 56 , name: 'English' , locale: 'en-EN' , direction: 'LRM' , isDefault: true , isBestFit: true ),
40
- Language (id: 7 , name: 'German (Austria)' , locale: 'de-AT' , direction: 'LRM' , isDefault: false , isBestFit: false ),
40
+ final _languages = [
41
+ LocalizeIndex (id : 1216 , url : null , lastUpdatedAt : null , shouldUpdate : false , language : Language (id: 56 , name: 'English' , locale: 'en-EN' , direction: 'LRM' , isDefault: true , isBestFit: true ) ),
42
+ LocalizeIndex (id : 1270 , url : null , lastUpdatedAt : null , shouldUpdate : false , language : Language (id: 7 , name: 'German (Austria)' , locale: 'de-AT' , direction: 'LRM' , isDefault: false , isBestFit: false ) ),
41
43
];
42
44
43
45
const _bundledTranslations = {
44
- 'en-EN' : r'''{"data":{"default":{"title":"NStack SDK Demo","test":"test"},"test":{"testDollarSign":"$testing","testSingleQuotationMark":"'testing'","testDoubleQuotationMark":"\"testing\"","testMultipleLines":"testing\nmultiple\nlines"}},"meta":{"language":{"id":56,"name":"English","locale":"en-EN","direction":"LRM","is_default":false,"is_best_fit":false},"platform":{"id":515,"slug":"mobile"}}}''' ,
46
+ 'en-EN' : r'''{"data":{"default":{"title":"NStack SDK Demo","test":"test"},"test":{"testDollarSign":"$testing change back ","testSingleQuotationMark":"'testing'","testDoubleQuotationMark":"\"testing\"","testMultipleLines":"testing\nmultiple\nlines"}},"meta":{"language":{"id":56,"name":"English","locale":"en-EN","direction":"LRM","is_default":false,"is_best_fit":false},"platform":{"id":515,"slug":"mobile"}}}''' ,
45
47
'de-AT' : r'''{"data":{"default":{"title":"NStack SDK Demo","test":"test"},"test":{"testDollarSign":"__testDollarSign","testSingleQuotationMark":"__testSingleQuotationMark","testDoubleQuotationMark":"__testDoubleQuotationMark","testMultipleLines":"__testMultipleLines"}},"meta":{"language":{"id":7,"name":"German (Austria)","locale":"de-AT","direction":"LRM","is_default":false,"is_best_fit":false},"platform":{"id":515,"slug":"mobile"}}}''' ,
46
48
};
47
49
@@ -51,55 +53,85 @@ final _nstack = NStack<Localization>(
51
53
availableLanguages: _languages,
52
54
bundledTranslations: _bundledTranslations,
53
55
pickedLanguageLocale: '' ,
56
+ debug: kDebugMode
54
57
);
55
58
56
- class NStackWidget extends InheritedWidget {
57
- final NStack <Localization > nstack = _nstack;
59
+ class NStackScope extends InheritedWidget {
60
+ final NStack <Localization > nstack;
61
+ final NStackState state;
62
+ final String checksum;
58
63
59
- NStackWidget ({Key ? key, required Widget child})
64
+ NStackScope ({Key ? key, required Widget child, required this .state, required this .nstack, required this .checksum })
60
65
: super (key: key, child: child);
61
66
62
- static NStack of (BuildContext context) =>
63
- context.dependOnInheritedWidgetOfExactType <NStackWidget >()! .nstack ;
67
+ static NStackState of (BuildContext context) =>
68
+ context.dependOnInheritedWidgetOfExactType <NStackScope >()! .state ;
64
69
65
70
@override
66
- bool updateShouldNotify (NStackWidget oldWidget) =>
67
- nstack != oldWidget.nstack ;
71
+ bool updateShouldNotify (NStackScope oldWidget) =>
72
+ checksum != oldWidget.checksum ;
68
73
}
69
74
70
- class NStackInitWidget extends StatefulWidget {
75
+ class NStackWidget extends StatefulWidget {
71
76
final Widget child;
72
77
73
- const NStackInitWidget ({Key ? key, required Widget child})
78
+ const NStackWidget ({Key ? key, required Widget child})
74
79
: child = child,
75
80
super (key: key);
76
81
77
82
@override
78
- _NStackInitState createState () => _NStackInitState ();
83
+ NStackState createState () => NStackState ();
79
84
}
80
85
81
- class _NStackInitState extends State <NStackInitWidget > {
82
- static bool _initialized = false ;
86
+ class NStackState extends State <NStackWidget > {
87
+ final NStack < Localization > nstack = _nstack ;
83
88
84
- void setupNStack (BuildContext context) {
85
- final locale = Localizations .localeOf (context);
86
- final nstack = NStackWidget .of (context);
87
- nstack.appOpen (locale);
89
+ changeLanguage (Locale locale) async {
90
+ await _nstack.changeLocalization (locale).whenComplete (() => setState (() {}));
91
+ }
92
+
93
+ Future <void > appOpen (Locale locale) async {
94
+ await _nstack.appOpen (locale).whenComplete (() => setState (() {}));
88
95
}
89
96
90
97
@override
91
98
Widget build (BuildContext context) {
92
- if (! _initialized) {
93
- setupNStack (context);
94
- _initialized = true ;
99
+ return NStackScope (child: widget.child, state: this , nstack: this .nstack, checksum: nstack.checksum,);
100
+ }
101
+ }
102
+
103
+ class NStackAppOpen extends StatefulWidget {
104
+ const NStackAppOpen ({
105
+ Key ? key,
106
+ required this .child,
107
+ this .onComplete,
108
+ }) : super (key: key);
109
+
110
+ final Widget child;
111
+ final VoidCallback ? onComplete;
112
+
113
+ @override
114
+ _NStackAppOpenState createState () => _NStackAppOpenState ();
115
+ }
116
+
117
+ class _NStackAppOpenState extends State <NStackAppOpen > {
118
+ bool _initializedNStack = false ;
119
+
120
+ @override
121
+ Widget build (BuildContext context) {
122
+ if (! _initializedNStack) {
123
+ NStackScope .of (context)
124
+ .appOpen (Localizations .localeOf (context))
125
+ .whenComplete (() => widget.onComplete? .call ());
126
+ _initializedNStack = true ;
95
127
}
96
128
return widget.child;
97
129
}
98
130
}
99
131
100
132
/// Allows to access the Nstack Localization using the BuildContext
101
133
extension NStackWidgetExtension on BuildContext {
102
- Localization get localization => NStackWidget .of (this ).localization;
134
+ Localization get localization => NStackScope .of (this ).nstack .localization;
103
135
}
104
136
105
137
/// Allows to access the Nstack Localization from StatefulWidget's State
0 commit comments