Skip to content

Commit 61bdad2

Browse files
authored
fix: Format generated code (#43)
1 parent da4c3df commit 61bdad2

File tree

4 files changed

+86
-43
lines changed

4 files changed

+86
-43
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies:
2020
nstack:
2121
git:
2222
url: git://github.com/nstack-io/flutter-sdk.git
23-
ref: v0.5.0
23+
ref: v0.5.1
2424

2525
dev_dependencies:
2626
build_runner:

example/lib/nstack.dart

Lines changed: 81 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
1818
class 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

2525
class _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

3232
class _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\nmultiple\nlines\nupdated");
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\nmultiple\nlines\nupdated");
3942
}
4043

41-
const _config = NStackConfig(projectId: 'h6wJremI2TGFM88gbLkdyljWQuwf2hxhxvCH', apiKey: 'zp2S18H32b67eYAbRQh94tVw76ZzaKKXlHjd');
42-
44+
const _config = NStackConfig(
45+
projectId: 'h6wJremI2TGFM88gbLkdyljWQuwf2hxhxvCH',
46+
apiKey: 'zp2S18H32b67eYAbRQh94tVw76ZzaKKXlHjd');
47+
4348
final _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

4875
const _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

5382
final _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

6290
class 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

91125
class 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
129171
extension 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
134176
extension NStackStateExtension<T extends StatefulWidget> on State<T> {
135-
Localization get localization => context.localization;
177+
Localization get localization => context.localization;
136178
}
137-

lib/src/nstack_builder.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:nstack/models/nstack_config.dart';
99
import 'package:nstack/other/extensions.dart';
1010
import 'package:nstack/other/reserved_keywords.dart';
1111
import 'package:nstack/src/nstack_repository.dart';
12+
import 'package:dart_style/dart_style.dart';
1213

1314
/// A builder which outputs a 'nstack.dart' file. This file provides a NStack instance, type safe section key accessors and all bundled translations.
1415
class NstackBuilder implements Builder {
@@ -81,7 +82,8 @@ class NstackBuilder implements Builder {
8182
print(s);
8283
}
8384

84-
await buildStep.writeAsString(outputId, output.toString());
85+
final outputFormatted = DartFormatter().format(output.toString());
86+
await buildStep.writeAsString(outputId, outputFormatted);
8587
}
8688

8789
void _writeHeader(StringBuffer output) {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: nstack
22
description: Nstack plugin for Flutter.
3-
version: 0.5.0
3+
version: 0.5.1
44
homepage: https://github.com/nstack-io/flutter-sdk
55

66
environment:

0 commit comments

Comments
 (0)