Skip to content

⚡️ Format Dart files with the current Dart version instead of the latest supported #620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ analyzer:

linter:
rules:
always_use_package_imports: true
# always_use_package_imports: true
avoid_equals_and_hash_code_on_mutable_classes: true
avoid_classes_with_only_static_members: true
directives_ordering: true
Expand Down
201 changes: 101 additions & 100 deletions examples/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,121 +4,122 @@ import 'package:example/gen/fonts.gen.dart';
import 'package:example_resources/gen/assets.gen.dart';
import 'package:flutter/material.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
// await Firebase.initializeApp(
// options: DefaultFirebaseOptions.currentPlatform,
// );

// flavors sample
// output: {'extern'}
void main() {
print(MyAssets.images.chip4.chip4.flavors);
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

runApp(MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// Auto generated font from FlutterGen.
fontFamily: MyFontFamily.raleway,
primarySwatch: MyColorName.crimsonRed,
),
home: Scaffold(
appBar: AppBar(
title: const Text('FlutterGen'),
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// Auto generated font from FlutterGen.
fontFamily: MyFontFamily.raleway,
primarySwatch: MyColorName.crimsonRed,
),
body: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// Auto generated image from FlutterGen.
SizedBox(
width: 200,
height: 200,
child: MyAssets.rive.vehicles.rive(
fit: BoxFit.contain,
home: Scaffold(
appBar: AppBar(
title: const Text('FlutterGen'),
),
body: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// Auto generated image from FlutterGen.
SizedBox(
width: 200,
height: 200,
child: MyAssets.rive.vehicles.rive(
fit: BoxFit.contain,
),
),
),
SizedBox(
width: 200,
height: 200,
child: MyAssets.lottie.hamburgerArrow.lottie(
fit: BoxFit.contain,
SizedBox(
width: 200,
height: 200,
child: MyAssets.lottie.hamburgerArrow.lottie(
fit: BoxFit.contain,
),
),
),
SizedBox(
width: 200,
height: 200,
child: MyAssets.lottie.geometricalAnimation.lottie(
fit: BoxFit.contain,
SizedBox(
width: 200,
height: 200,
child: MyAssets.lottie.geometricalAnimation.lottie(
fit: BoxFit.contain,
),
),
),
SizedBox(
width: 200,
height: 200,
child: MyAssets.lottie.alarmClockLottieV440.lottie(
fit: BoxFit.contain,
SizedBox(
width: 200,
height: 200,
child: MyAssets.lottie.alarmClockLottieV440.lottie(
fit: BoxFit.contain,
),
),
),
MyAssets.images.chip1.image(),
Container(
height: 400,
decoration: BoxDecoration(
image: DecorationImage(
image: MyAssets.images.chip1.provider(),
MyAssets.images.chip1.image(),
Container(
height: 400,
decoration: BoxDecoration(
image: DecorationImage(
image: MyAssets.images.chip1.provider(),
),
),
child: const Center(child: Text('Deco')),
),
// Use from example_resource package.
MyAssets.images.icons.kmm.svg(key: const Key('kmm_svg')),
MyAssets.images.icons.fuchsia.svg(),
MyAssets.images.icons.paint.svg(
width: 120,
height: 120,
),
child: const Center(child: Text('Deco')),
),
// Use from example_resource package.
MyAssets.images.icons.kmm.svg(key: const Key('kmm_svg')),
MyAssets.images.icons.fuchsia.svg(),
MyAssets.images.icons.paint.svg(
width: 120,
height: 120,
),
// MyAssets.pictures.chip5.image(
// key: const Key("chip5"),
// width: 120,
// height: 120,
// fit: BoxFit.scaleDown,
// ),
// MyAssets.pictures.chip5.image(
// key: const Key("chip5"),
// width: 120,
// height: 120,
// fit: BoxFit.scaleDown,
// ),

// example_resource package.
Text(MyAssets.images.icons.kmm.path),
Text(MyAssets.images.icons.kmm.keyName),
Text(ResAssets.images.dart.path),
Text(ResAssets.images.dart.keyName),
ResAssets.images.flutter3.image(),
ResAssets.images.dart.svg(),
SizedBox(
width: 200,
height: 200,
child: ResAssets.images.skills.rive(
fit: BoxFit.contain,
// example_resource package.
Text(MyAssets.images.icons.kmm.path),
Text(MyAssets.images.icons.kmm.keyName),
Text(ResAssets.images.dart.path),
Text(ResAssets.images.dart.keyName),
ResAssets.images.flutter3.image(),
ResAssets.images.dart.svg(),
SizedBox(
width: 200,
height: 200,
child: ResAssets.images.skills.rive(
fit: BoxFit.contain,
),
),
),
SizedBox(
width: 200,
height: 200,
child: ResAssets.images.runningCarOnRoad.lottie(
fit: BoxFit.contain,
SizedBox(
width: 200,
height: 200,
child: ResAssets.images.runningCarOnRoad.lottie(
fit: BoxFit.contain,
),
),
),
const Text(
'Hi there, I\'m FlutterGen',
style: TextStyle(
// Auto generated color from FlutterGen.
color: MyColorName.black60,
const Text(
'Hi there, I\'m FlutterGen',
style: TextStyle(
// Auto generated color from FlutterGen.
color: MyColorName.black60,

// Auto generated font from FlutterGen.
fontFamily: MyFontFamily.robotoMono,
fontFamilyFallback: [MyFontFamily.raleway],
// Auto generated font from FlutterGen.
fontFamily: MyFontFamily.robotoMono,
fontFamilyFallback: [MyFontFamily.raleway],
),
),
),
],
],
),
),
),
),
),
));
);
}
}
12 changes: 4 additions & 8 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@ command:
description: flutter clean

scripts:
get:
run: flutter pub get
exec:
concurrency: 1
description: flutter pub get

upgrade:
run: flutter pub upgrade
run: dart pub upgrade
exec:
concurrency: 1
description: flutter pub upgrade
packageFilters:
flutter: false
description: dart pub upgrade

analyze:
exec: flutter analyze
Expand Down
9 changes: 5 additions & 4 deletions packages/core/lib/flutter_generator.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'dart:io';
import 'dart:io' show stdout, Directory, File, Platform;

import 'package:dart_style/dart_style.dart';
import 'package:dart_style/dart_style.dart' show DartFormatter;
import 'package:flutter_gen_core/generators/assets_generator.dart';
import 'package:flutter_gen_core/generators/colors_generator.dart';
import 'package:flutter_gen_core/generators/fonts_generator.dart';
import 'package:flutter_gen_core/settings/config.dart';
import 'package:flutter_gen_core/utils/file.dart';
import 'package:path/path.dart';
import 'package:path/path.dart' show join, normalize;
import 'package:pub_semver/pub_semver.dart' show Version;

class FlutterGenerator {
const FlutterGenerator(
Expand All @@ -32,7 +33,7 @@ class FlutterGenerator {
final output = config.pubspec.flutterGen.output;
final lineLength = config.pubspec.flutterGen.lineLength;
final formatter = DartFormatter(
languageVersion: DartFormatter.latestLanguageVersion,
languageVersion: Version.parse(Platform.version.split(' ').first),
pageWidth: lineLength,
lineEnding: '\n',
);
Expand Down
41 changes: 17 additions & 24 deletions packages/core/lib/settings/asset_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,35 @@ class AssetType {
final Set<String> flavors;

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

bool get isDefaultAssetsDirectory => path == 'assets' || path == 'asset';
late final isDefaultAssetsDirectory = path == 'assets' || path == 'asset';
late final mime = lookupMimeType(path);
late final isUnKnownMime = mime == null;

String? get mime => lookupMimeType(path);
/// Returns a name for this asset.
late final name = p.withoutExtension(path);
late final baseName = p.basenameWithoutExtension(path);
late final extension = p.extension(path);

/// Returns the full absolute path for reading the asset file.
late final fullPath = p.join(rootPath, path);

// Replace to Posix style for Windows separator.
late final posixStylePath = path.replaceAll(r'\', r'/');

bool get isIgnoreFile {
late final bool isIgnoreFile = () {
switch (baseName) {
case '.DS_Store':
return true;
}

switch (extension) {
case '.DS_Store':
case '.swp':
return true;
}

return false;
}

bool get isUnKnownMime => mime == null;

/// Returns a name for this asset.
String get name => p.withoutExtension(path);

String get baseName => p.basenameWithoutExtension(path);

String get extension => p.extension(path);

/// Returns the full absolute path for reading the asset file.
String get fullPath => p.join(rootPath, path);

// Replace to Posix style for Windows separator.
String get posixStylePath => path.replaceAll(r'\', r'/');

List<AssetType> get children => _children.sortedBy((e) => e.path);
}();

void addChild(AssetType type) {
_children.add(type);
Expand Down Expand Up @@ -125,7 +118,7 @@ class UniqueAssetType extends AssetType {
}

extension AssetTypeIterable on Iterable<AssetType> {
/// Takes a Iterable<AssetType> and mutates the AssetType's to ensure each
/// Takes a `Iterable<AssetType>` and mutates the AssetType's to ensure each
/// AssetType has a unique name.
///
/// The strategy is as follows:
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/assets_gen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void main() {
final pubspec = File('test_resources/pubspec_assets_no_list.yaml');
final config = loadPubspecConfig(pubspec);
final formatter = DartFormatter(
languageVersion: DartFormatter.latestLanguageVersion,
languageVersion: currentDartVersion,
pageWidth: config.pubspec.flutterGen.lineLength,
lineEnding: '\n',
);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/colors_gen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() {
final pubspec = File('test_resources/pubspec_colors_no_inputs.yaml');
final config = loadPubspecConfig(pubspec);
final formatter = DartFormatter(
languageVersion: DartFormatter.latestLanguageVersion,
languageVersion: currentDartVersion,
pageWidth: config.pubspec.flutterGen.lineLength,
lineEnding: '\n',
);
Expand All @@ -38,7 +38,7 @@ void main() {
final pubspec = File('test_resources/pubspec_colors_no_inputs_list.yaml');
final config = loadPubspecConfig(pubspec);
final formatter = DartFormatter(
languageVersion: DartFormatter.latestLanguageVersion,
languageVersion: currentDartVersion,
pageWidth: config.pubspec.flutterGen.lineLength,
lineEnding: '\n',
);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/fonts_gen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() {
File('test_resources/pubspec_fonts_no_family.yaml'),
);
final formatter = DartFormatter(
languageVersion: DartFormatter.latestLanguageVersion,
languageVersion: currentDartVersion,
pageWidth: config.pubspec.flutterGen.lineLength,
lineEnding: '\n',
);
Expand Down
Loading
Loading