@@ -14,58 +14,91 @@ export 'package:nstack/models/app_open_platform.dart';
1414// Update this file by running:
1515// - `flutter pub run build_runner build`, if your package depends on Flutter
1616// - `pub run build_runner build` otherwise
17-
17+
1818class Localization {
19- final defaultSection = const _DefaultSection ();
20- final test = const _Test ();
19+ final defaultSection = const _DefaultSection ();
20+ final test = const _Test ();
2121
22- const Localization ();
22+ const Localization ();
2323}
2424
2525class _DefaultSection extends SectionKeyDelegate {
26- const _DefaultSection (): super ('default' );
26+ const _DefaultSection () : super ('default' );
2727
28- String get title => get ('title' , "NStack SDK Demo" );
29- String get test => get ('test' , "test" );
28+ String get title => get ('title' , "NStack SDK Demo" );
29+ String get test => get ('test' , "test" );
3030}
3131
3232class _Test extends SectionKeyDelegate {
33- const _Test (): super ('test' );
34-
35- String get testDollarSign => get ('testDollarSign' , "\$ testing again new" );
36- String get testSingleQuotationMark => get ('testSingleQuotationMark' , "\' testing\' " );
37- String get testDoubleQuotationMark => get ('testDoubleQuotationMark' , "\" testing\" " );
38- String get testMultipleLines => get ('testMultipleLines' , "testing\n multiple\n lines\n updated" );
33+ const _Test () : super ('test' );
34+
35+ String get testDollarSign => get ('testDollarSign' , "\$ testing again new" );
36+ String get testSingleQuotationMark =>
37+ get ('testSingleQuotationMark' , "\' testing\' " );
38+ String get testDoubleQuotationMark =>
39+ get ('testDoubleQuotationMark' , "\" testing\" " );
40+ String get testMultipleLines =>
41+ get ('testMultipleLines' , "testing\n multiple\n lines\n updated" );
3942}
4043
41- const _config = NStackConfig (projectId: 'h6wJremI2TGFM88gbLkdyljWQuwf2hxhxvCH' , apiKey: 'zp2S18H32b67eYAbRQh94tVw76ZzaKKXlHjd' );
42-
44+ const _config = NStackConfig (
45+ projectId: 'h6wJremI2TGFM88gbLkdyljWQuwf2hxhxvCH' ,
46+ apiKey: 'zp2S18H32b67eYAbRQh94tVw76ZzaKKXlHjd' );
47+
4348final _languages = [
44- LocalizeIndex (id: 1216 , url: null , lastUpdatedAt: null , shouldUpdate: false , language: Language (id: 56 , name: 'English' , locale: 'en-EN' , direction: 'LRM' , isDefault: true , isBestFit: true )),
45- 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 )),
49+ LocalizeIndex (
50+ id: 1216 ,
51+ url: null ,
52+ lastUpdatedAt: null ,
53+ shouldUpdate: false ,
54+ language: Language (
55+ id: 56 ,
56+ name: 'English' ,
57+ locale: 'en-EN' ,
58+ direction: 'LRM' ,
59+ isDefault: true ,
60+ isBestFit: true )),
61+ LocalizeIndex (
62+ id: 1270 ,
63+ url: null ,
64+ lastUpdatedAt: null ,
65+ shouldUpdate: false ,
66+ language: Language (
67+ id: 7 ,
68+ name: 'German (Austria)' ,
69+ locale: 'de-AT' ,
70+ direction: 'LRM' ,
71+ isDefault: false ,
72+ isBestFit: false )),
4673];
4774
4875const _bundledTranslations = {
49- 'en-EN' : r'''{"data":{"default":{"title":"NStack SDK Demo","test":"test"},"test":{"testDollarSign":"$testing again new","testSingleQuotationMark":"'testing'","testDoubleQuotationMark":"\"testing\"","testMultipleLines":"testing\nmultiple\nlines\nupdated"}},"meta":{"language":{"id":56,"name":"English","locale":"en-EN","direction":"LRM","is_default":false,"is_best_fit":false},"platform":{"id":515,"slug":"mobile"}}}''' ,
50- '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"}}}''' ,
76+ 'en-EN' :
77+ r'''{"data":{"default":{"title":"NStack SDK Demo","test":"test"},"test":{"testDollarSign":"$testing again new","testSingleQuotationMark":"'testing'","testDoubleQuotationMark":"\"testing\"","testMultipleLines":"testing\nmultiple\nlines\nupdated"}},"meta":{"language":{"id":56,"name":"English","locale":"en-EN","direction":"LRM","is_default":false,"is_best_fit":false},"platform":{"id":515,"slug":"mobile"}}}''' ,
78+ 'de-AT' :
79+ r'''{"data":{"default":{"title":"NStack SDK Demo","test":"test"},"test":{"testDollarSign":"\u00a0","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"}}}''' ,
5180};
5281
5382final _nstack = NStack <Localization >(
54- config: _config,
55- localization: const Localization (),
56- availableLanguages: _languages,
57- bundledTranslations: _bundledTranslations,
58- pickedLanguageLocale: '' ,
59- debug: kDebugMode
60- );
83+ config: _config,
84+ localization: const Localization (),
85+ availableLanguages: _languages,
86+ bundledTranslations: _bundledTranslations,
87+ pickedLanguageLocale: '' ,
88+ debug: kDebugMode);
6189
6290class NStackScope extends InheritedWidget {
6391 final NStack <Localization > nstack;
6492 final NStackState state;
6593 final String checksum;
6694
67- NStackScope ({Key ? key, required Widget child, required this .state, required this .nstack, required this .checksum})
68- : super (key: key, child: child);
95+ NStackScope (
96+ {Key ? key,
97+ required Widget child,
98+ required this .state,
99+ required this .nstack,
100+ required this .checksum})
101+ : super (key: key, child: child);
69102
70103 static NStackState of (BuildContext context) =>
71104 context.dependOnInheritedWidgetOfExactType <NStackScope >()! .state;
@@ -80,7 +113,8 @@ class NStackWidget extends StatefulWidget {
80113 final AppOpenPlatform ? platformOverride;
81114 final VoidCallback ? onComplete;
82115
83- const NStackWidget ({Key ? key, required Widget child, this .platformOverride, this .onComplete})
116+ const NStackWidget (
117+ {Key ? key, required Widget child, this .platformOverride, this .onComplete})
84118 : child = child,
85119 super (key: key);
86120
@@ -89,35 +123,43 @@ class NStackWidget extends StatefulWidget {
89123}
90124
91125class NStackState extends State <NStackWidget > {
92- final NStack <Localization > nstack = _nstack;
126+ final NStack <Localization > nstack = _nstack;
93127 bool _initializedNStack = false ;
94128
95129 late Future <bool > _nstackInitFuture;
96130
97131 @override
98132 void initState () {
99133 super .initState ();
100- _nstackInitFuture = _nstack.init ();
134+ _nstackInitFuture = _nstack.init ();
101135 }
102136
103- changeLanguage (Locale locale) async {
104- await _nstack.changeLocalization (locale).whenComplete (() => setState (() {}));
105- }
137+ changeLanguage (Locale locale) async {
138+ await _nstack
139+ .changeLocalization (locale)
140+ .whenComplete (() => setState (() {}));
141+ }
106142
107143 @override
108144 Widget build (BuildContext context) {
109145 if (! _initializedNStack) {
110146 _nstack
111- .appOpen (Localizations .localeOf (context), platformOverride: widget.platformOverride)
147+ .appOpen (Localizations .localeOf (context),
148+ platformOverride: widget.platformOverride)
112149 .whenComplete (() => widget.onComplete? .call ());
113150 _initializedNStack = true ;
114151 }
115152
116153 return FutureBuilder (
117154 future: _nstackInitFuture,
118155 builder: (context, snapshot) {
119- if (snapshot.connectionState == ConnectionState .done) {
120- return NStackScope (child: widget.child, state: this , nstack: this .nstack, checksum: nstack.checksum,);
156+ if (snapshot.connectionState == ConnectionState .done) {
157+ return NStackScope (
158+ child: widget.child,
159+ state: this ,
160+ nstack: this .nstack,
161+ checksum: nstack.checksum,
162+ );
121163 } else {
122164 return SizedBox ();
123165 }
@@ -127,11 +169,10 @@ class NStackState extends State<NStackWidget> {
127169
128170/// Allows to access the Nstack Localization using the BuildContext
129171extension NStackWidgetExtension on BuildContext {
130- Localization get localization => NStackScope .of (this ).nstack.localization;
172+ Localization get localization => NStackScope .of (this ).nstack.localization;
131173}
132174
133175/// Allows to access the Nstack Localization from StatefulWidget's State
134176extension NStackStateExtension <T extends StatefulWidget > on State <T > {
135- Localization get localization => context.localization;
177+ Localization get localization => context.localization;
136178}
137-
0 commit comments