Skip to content

Commit 5ad4f6c

Browse files
authored
⚡️ Format Dart files with the current Dart version instead of the latest supported (#620)
## Type of change - [x] Bug fix (non-breaking change which fixes an issue)
1 parent b7f9aa4 commit 5ad4f6c

File tree

9 files changed

+138
-144
lines changed

9 files changed

+138
-144
lines changed

analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ analyzer:
1313

1414
linter:
1515
rules:
16-
always_use_package_imports: true
16+
# always_use_package_imports: true
1717
avoid_equals_and_hash_code_on_mutable_classes: true
1818
avoid_classes_with_only_static_members: true
1919
directives_ordering: true

examples/example/lib/main.dart

Lines changed: 101 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -4,121 +4,122 @@ import 'package:example/gen/fonts.gen.dart';
44
import 'package:example_resources/gen/assets.gen.dart';
55
import 'package:flutter/material.dart';
66

7-
void main() async {
8-
WidgetsFlutterBinding.ensureInitialized();
9-
// await Firebase.initializeApp(
10-
// options: DefaultFirebaseOptions.currentPlatform,
11-
// );
12-
13-
// flavors sample
14-
// output: {'extern'}
7+
void main() {
158
print(MyAssets.images.chip4.chip4.flavors);
9+
runApp(const MyApp());
10+
}
11+
12+
class MyApp extends StatelessWidget {
13+
const MyApp({super.key});
1614

17-
runApp(MaterialApp(
18-
title: 'Flutter Demo',
19-
theme: ThemeData(
20-
// Auto generated font from FlutterGen.
21-
fontFamily: MyFontFamily.raleway,
22-
primarySwatch: MyColorName.crimsonRed,
23-
),
24-
home: Scaffold(
25-
appBar: AppBar(
26-
title: const Text('FlutterGen'),
15+
@override
16+
Widget build(BuildContext context) {
17+
return MaterialApp(
18+
title: 'Flutter Demo',
19+
theme: ThemeData(
20+
// Auto generated font from FlutterGen.
21+
fontFamily: MyFontFamily.raleway,
22+
primarySwatch: MyColorName.crimsonRed,
2723
),
28-
body: Center(
29-
child: SingleChildScrollView(
30-
child: Column(
31-
mainAxisAlignment: MainAxisAlignment.center,
32-
children: <Widget>[
33-
// Auto generated image from FlutterGen.
34-
SizedBox(
35-
width: 200,
36-
height: 200,
37-
child: MyAssets.rive.vehicles.rive(
38-
fit: BoxFit.contain,
24+
home: Scaffold(
25+
appBar: AppBar(
26+
title: const Text('FlutterGen'),
27+
),
28+
body: Center(
29+
child: SingleChildScrollView(
30+
child: Column(
31+
mainAxisAlignment: MainAxisAlignment.center,
32+
children: <Widget>[
33+
// Auto generated image from FlutterGen.
34+
SizedBox(
35+
width: 200,
36+
height: 200,
37+
child: MyAssets.rive.vehicles.rive(
38+
fit: BoxFit.contain,
39+
),
3940
),
40-
),
41-
SizedBox(
42-
width: 200,
43-
height: 200,
44-
child: MyAssets.lottie.hamburgerArrow.lottie(
45-
fit: BoxFit.contain,
41+
SizedBox(
42+
width: 200,
43+
height: 200,
44+
child: MyAssets.lottie.hamburgerArrow.lottie(
45+
fit: BoxFit.contain,
46+
),
4647
),
47-
),
48-
SizedBox(
49-
width: 200,
50-
height: 200,
51-
child: MyAssets.lottie.geometricalAnimation.lottie(
52-
fit: BoxFit.contain,
48+
SizedBox(
49+
width: 200,
50+
height: 200,
51+
child: MyAssets.lottie.geometricalAnimation.lottie(
52+
fit: BoxFit.contain,
53+
),
5354
),
54-
),
55-
SizedBox(
56-
width: 200,
57-
height: 200,
58-
child: MyAssets.lottie.alarmClockLottieV440.lottie(
59-
fit: BoxFit.contain,
55+
SizedBox(
56+
width: 200,
57+
height: 200,
58+
child: MyAssets.lottie.alarmClockLottieV440.lottie(
59+
fit: BoxFit.contain,
60+
),
6061
),
61-
),
62-
MyAssets.images.chip1.image(),
63-
Container(
64-
height: 400,
65-
decoration: BoxDecoration(
66-
image: DecorationImage(
67-
image: MyAssets.images.chip1.provider(),
62+
MyAssets.images.chip1.image(),
63+
Container(
64+
height: 400,
65+
decoration: BoxDecoration(
66+
image: DecorationImage(
67+
image: MyAssets.images.chip1.provider(),
68+
),
6869
),
70+
child: const Center(child: Text('Deco')),
71+
),
72+
// Use from example_resource package.
73+
MyAssets.images.icons.kmm.svg(key: const Key('kmm_svg')),
74+
MyAssets.images.icons.fuchsia.svg(),
75+
MyAssets.images.icons.paint.svg(
76+
width: 120,
77+
height: 120,
6978
),
70-
child: const Center(child: Text('Deco')),
71-
),
72-
// Use from example_resource package.
73-
MyAssets.images.icons.kmm.svg(key: const Key('kmm_svg')),
74-
MyAssets.images.icons.fuchsia.svg(),
75-
MyAssets.images.icons.paint.svg(
76-
width: 120,
77-
height: 120,
78-
),
79-
// MyAssets.pictures.chip5.image(
80-
// key: const Key("chip5"),
81-
// width: 120,
82-
// height: 120,
83-
// fit: BoxFit.scaleDown,
84-
// ),
79+
// MyAssets.pictures.chip5.image(
80+
// key: const Key("chip5"),
81+
// width: 120,
82+
// height: 120,
83+
// fit: BoxFit.scaleDown,
84+
// ),
8585

86-
// example_resource package.
87-
Text(MyAssets.images.icons.kmm.path),
88-
Text(MyAssets.images.icons.kmm.keyName),
89-
Text(ResAssets.images.dart.path),
90-
Text(ResAssets.images.dart.keyName),
91-
ResAssets.images.flutter3.image(),
92-
ResAssets.images.dart.svg(),
93-
SizedBox(
94-
width: 200,
95-
height: 200,
96-
child: ResAssets.images.skills.rive(
97-
fit: BoxFit.contain,
86+
// example_resource package.
87+
Text(MyAssets.images.icons.kmm.path),
88+
Text(MyAssets.images.icons.kmm.keyName),
89+
Text(ResAssets.images.dart.path),
90+
Text(ResAssets.images.dart.keyName),
91+
ResAssets.images.flutter3.image(),
92+
ResAssets.images.dart.svg(),
93+
SizedBox(
94+
width: 200,
95+
height: 200,
96+
child: ResAssets.images.skills.rive(
97+
fit: BoxFit.contain,
98+
),
9899
),
99-
),
100-
SizedBox(
101-
width: 200,
102-
height: 200,
103-
child: ResAssets.images.runningCarOnRoad.lottie(
104-
fit: BoxFit.contain,
100+
SizedBox(
101+
width: 200,
102+
height: 200,
103+
child: ResAssets.images.runningCarOnRoad.lottie(
104+
fit: BoxFit.contain,
105+
),
105106
),
106-
),
107-
const Text(
108-
'Hi there, I\'m FlutterGen',
109-
style: TextStyle(
110-
// Auto generated color from FlutterGen.
111-
color: MyColorName.black60,
107+
const Text(
108+
'Hi there, I\'m FlutterGen',
109+
style: TextStyle(
110+
// Auto generated color from FlutterGen.
111+
color: MyColorName.black60,
112112

113-
// Auto generated font from FlutterGen.
114-
fontFamily: MyFontFamily.robotoMono,
115-
fontFamilyFallback: [MyFontFamily.raleway],
113+
// Auto generated font from FlutterGen.
114+
fontFamily: MyFontFamily.robotoMono,
115+
fontFamilyFallback: [MyFontFamily.raleway],
116+
),
116117
),
117-
),
118-
],
118+
],
119+
),
119120
),
120121
),
121122
),
122-
),
123-
));
123+
);
124+
}
124125
}

melos.yaml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,13 @@ command:
2020
description: flutter clean
2121

2222
scripts:
23-
get:
24-
run: flutter pub get
25-
exec:
26-
concurrency: 1
27-
description: flutter pub get
28-
2923
upgrade:
30-
run: flutter pub upgrade
24+
run: dart pub upgrade
3125
exec:
3226
concurrency: 1
33-
description: flutter pub upgrade
27+
packageFilters:
28+
flutter: false
29+
description: dart pub upgrade
3430

3531
analyze:
3632
exec: flutter analyze

packages/core/lib/flutter_generator.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import 'dart:io';
1+
import 'dart:io' show stdout, Directory, File, Platform;
22

3-
import 'package:dart_style/dart_style.dart';
3+
import 'package:dart_style/dart_style.dart' show DartFormatter;
44
import 'package:flutter_gen_core/generators/assets_generator.dart';
55
import 'package:flutter_gen_core/generators/colors_generator.dart';
66
import 'package:flutter_gen_core/generators/fonts_generator.dart';
77
import 'package:flutter_gen_core/settings/config.dart';
88
import 'package:flutter_gen_core/utils/file.dart';
9-
import 'package:path/path.dart';
9+
import 'package:path/path.dart' show join, normalize;
10+
import 'package:pub_semver/pub_semver.dart' show Version;
1011

1112
class FlutterGenerator {
1213
const FlutterGenerator(
@@ -32,7 +33,7 @@ class FlutterGenerator {
3233
final output = config.pubspec.flutterGen.output;
3334
final lineLength = config.pubspec.flutterGen.lineLength;
3435
final formatter = DartFormatter(
35-
languageVersion: DartFormatter.latestLanguageVersion,
36+
languageVersion: Version.parse(Platform.version.split(' ').first),
3637
pageWidth: lineLength,
3738
lineEnding: '\n',
3839
);

packages/core/lib/settings/asset_type.dart

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,35 @@ class AssetType {
1717
final Set<String> flavors;
1818

1919
final List<AssetType> _children = List.empty(growable: true);
20+
late final children = _children.sortedBy((e) => e.path);
2021

21-
bool get isDefaultAssetsDirectory => path == 'assets' || path == 'asset';
22+
late final isDefaultAssetsDirectory = path == 'assets' || path == 'asset';
23+
late final mime = lookupMimeType(path);
24+
late final isUnKnownMime = mime == null;
2225

23-
String? get mime => lookupMimeType(path);
26+
/// Returns a name for this asset.
27+
late final name = p.withoutExtension(path);
28+
late final baseName = p.basenameWithoutExtension(path);
29+
late final extension = p.extension(path);
30+
31+
/// Returns the full absolute path for reading the asset file.
32+
late final fullPath = p.join(rootPath, path);
33+
34+
// Replace to Posix style for Windows separator.
35+
late final posixStylePath = path.replaceAll(r'\', r'/');
2436

25-
bool get isIgnoreFile {
37+
late final bool isIgnoreFile = () {
2638
switch (baseName) {
2739
case '.DS_Store':
2840
return true;
2941
}
30-
3142
switch (extension) {
3243
case '.DS_Store':
3344
case '.swp':
3445
return true;
3546
}
36-
3747
return false;
38-
}
39-
40-
bool get isUnKnownMime => mime == null;
41-
42-
/// Returns a name for this asset.
43-
String get name => p.withoutExtension(path);
44-
45-
String get baseName => p.basenameWithoutExtension(path);
46-
47-
String get extension => p.extension(path);
48-
49-
/// Returns the full absolute path for reading the asset file.
50-
String get fullPath => p.join(rootPath, path);
51-
52-
// Replace to Posix style for Windows separator.
53-
String get posixStylePath => path.replaceAll(r'\', r'/');
54-
55-
List<AssetType> get children => _children.sortedBy((e) => e.path);
48+
}();
5649

5750
void addChild(AssetType type) {
5851
_children.add(type);
@@ -125,7 +118,7 @@ class UniqueAssetType extends AssetType {
125118
}
126119

127120
extension AssetTypeIterable on Iterable<AssetType> {
128-
/// Takes a Iterable<AssetType> and mutates the AssetType's to ensure each
121+
/// Takes a `Iterable<AssetType>` and mutates the AssetType's to ensure each
129122
/// AssetType has a unique name.
130123
///
131124
/// The strategy is as follows:

packages/core/test/assets_gen_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void main() {
6060
final pubspec = File('test_resources/pubspec_assets_no_list.yaml');
6161
final config = loadPubspecConfig(pubspec);
6262
final formatter = DartFormatter(
63-
languageVersion: DartFormatter.latestLanguageVersion,
63+
languageVersion: currentDartVersion,
6464
pageWidth: config.pubspec.flutterGen.lineLength,
6565
lineEnding: '\n',
6666
);

packages/core/test/colors_gen_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void main() {
2323
final pubspec = File('test_resources/pubspec_colors_no_inputs.yaml');
2424
final config = loadPubspecConfig(pubspec);
2525
final formatter = DartFormatter(
26-
languageVersion: DartFormatter.latestLanguageVersion,
26+
languageVersion: currentDartVersion,
2727
pageWidth: config.pubspec.flutterGen.lineLength,
2828
lineEnding: '\n',
2929
);
@@ -38,7 +38,7 @@ void main() {
3838
final pubspec = File('test_resources/pubspec_colors_no_inputs_list.yaml');
3939
final config = loadPubspecConfig(pubspec);
4040
final formatter = DartFormatter(
41-
languageVersion: DartFormatter.latestLanguageVersion,
41+
languageVersion: currentDartVersion,
4242
pageWidth: config.pubspec.flutterGen.lineLength,
4343
lineEnding: '\n',
4444
);

packages/core/test/fonts_gen_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void main() {
2323
File('test_resources/pubspec_fonts_no_family.yaml'),
2424
);
2525
final formatter = DartFormatter(
26-
languageVersion: DartFormatter.latestLanguageVersion,
26+
languageVersion: currentDartVersion,
2727
pageWidth: config.pubspec.flutterGen.lineLength,
2828
lineEnding: '\n',
2929
);

0 commit comments

Comments
 (0)