This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
356 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"flutterSdkVersion": "3.7.12", | ||
"flavors": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 1.0.0 | ||
|
||
- Initial version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 K9i | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!-- | ||
This README describes the package. If you publish this package to pub.dev, | ||
this README's contents appear on the landing page for your package. | ||
For information about how to write a good package README, see the guide for | ||
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages). | ||
For general information about developing packages, see the Dart guide for | ||
[creating packages](https://dart.dev/guides/libraries/create-library-packages) | ||
and the Flutter guide for | ||
[developing packages and plugins](https://flutter.dev/developing-packages). | ||
--> | ||
|
||
TODO: Put a short description of the package here that helps potential users | ||
know whether this package might be useful for them. | ||
|
||
## Features | ||
|
||
TODO: List what your package can do. Maybe include images, gifs, or videos. | ||
|
||
## Getting started | ||
|
||
TODO: List prerequisites and provide or point to information on how to | ||
start using the package. | ||
|
||
## Usage | ||
|
||
TODO: Include short and useful examples for package users. Add longer examples | ||
to `/example` folder. | ||
|
||
```dart | ||
const like = 'sample'; | ||
``` | ||
|
||
## Additional information | ||
|
||
TODO: Tell users more about the package: where to find more information, how to | ||
contribute to the package, how to file issues, what response they can expect | ||
from the package authors, and more. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled. | ||
|
||
version: | ||
revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf | ||
channel: stable | ||
|
||
project_type: app | ||
|
||
# Tracks metadata for the flutter migrate command | ||
migration: | ||
platforms: | ||
- platform: root | ||
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf | ||
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf | ||
- platform: android | ||
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf | ||
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf | ||
- platform: ios | ||
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf | ||
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf | ||
- platform: web | ||
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf | ||
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf | ||
|
||
# User provided section | ||
|
||
# List of Local paths (relative to this file) that should be | ||
# ignored by the migrate tool. | ||
# | ||
# Files that are not part of the templates will be ignored by default. | ||
unmanaged_files: | ||
- 'lib/main.dart' | ||
- 'ios/Runner.xcodeproj/project.pbxproj' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# example | ||
|
||
A new Flutter project. |
4 changes: 4 additions & 0 deletions
4
packages/material_button_assist/example/analysis_options.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include: package:flutter_lints/flutter.yaml | ||
analyzer: | ||
plugins: | ||
- custom_lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
void main() { | ||
runApp(const MainApp()); | ||
} | ||
|
||
class MainApp extends StatelessWidget { | ||
const MainApp({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
theme: ThemeData( | ||
useMaterial3: true, | ||
), | ||
home: Scaffold( | ||
body: Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
children: [ | ||
ElevatedButton( | ||
onPressed: () {}, | ||
child: const Text('Hello World!'), | ||
), | ||
FilledButton.tonal( | ||
onPressed: () {}, | ||
child: const Text('Hello World!'), | ||
), | ||
FilledButton.tonal( | ||
onPressed: () {}, | ||
child: const Text('Hello World!'), | ||
), | ||
OutlinedButton( | ||
onPressed: () {}, | ||
child: const Text('Hello World!'), | ||
), | ||
TextButton( | ||
onPressed: () {}, | ||
child: const Text('Hello World!'), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: example | ||
description: A new Flutter project. | ||
publish_to: 'none' | ||
version: 0.1.0 | ||
|
||
environment: | ||
sdk: '>=2.19.6 <3.0.0' | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
|
||
dev_dependencies: | ||
flutter_test: | ||
sdk: flutter | ||
flutter_lints: ^2.0.1 | ||
custom_lint: ^0.3.4 | ||
material_button_assist: | ||
path: ../ | ||
|
||
flutter: | ||
uses-material-design: true |
4 changes: 4 additions & 0 deletions
4
packages/material_button_assist/example/pubspec_overrides.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# melos_managed_dependency_overrides: material_button_assist | ||
dependency_overrides: | ||
material_button_assist: | ||
path: .. |
18 changes: 18 additions & 0 deletions
18
packages/material_button_assist/lib/material_button_assist.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
library material_button_assist; | ||
|
||
import 'package:custom_lint_builder/custom_lint_builder.dart'; | ||
import 'package:material_button_assist/src/assists/convert_to_other_button.dart'; | ||
|
||
PluginBase createPlugin() => _MaterialButtonAssist(); | ||
|
||
class _MaterialButtonAssist extends PluginBase { | ||
@override | ||
List<LintRule> getLintRules(CustomLintConfigs configs) => const []; | ||
|
||
@override | ||
List<Assist> getAssists() => [ | ||
...MaterialButtonType.values | ||
.map((buttonType) => ConvertToOtherButton(targetType: buttonType)) | ||
.toList(), | ||
]; | ||
} |
133 changes: 133 additions & 0 deletions
133
packages/material_button_assist/lib/src/assists/convert_to_other_button.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import 'package:analyzer/source/source_range.dart'; | ||
import 'package:custom_lint_builder/custom_lint_builder.dart'; | ||
|
||
const convertToOtherButtonPriority = 26; | ||
|
||
enum MaterialButtonType { | ||
elevated( | ||
buttonName: 'ElevatedButton', | ||
constructorName: 'ElevatedButton', | ||
priority: convertToOtherButtonPriority, | ||
typeChecker: TypeChecker.fromName( | ||
'ElevatedButton', | ||
packageName: 'flutter', | ||
), | ||
), | ||
filled( | ||
buttonName: 'FilledButton', | ||
constructorName: 'FilledButton', | ||
priority: convertToOtherButtonPriority, | ||
typeChecker: TypeChecker.fromName( | ||
'FilledButton', | ||
packageName: 'flutter', | ||
), | ||
), | ||
filledTonal( | ||
buttonName: 'FilledTonalButton', | ||
constructorName: 'FilledButton.tonal', | ||
priority: convertToOtherButtonPriority, | ||
typeChecker: TypeChecker.fromName( | ||
'FilledButton', | ||
packageName: 'flutter', | ||
), | ||
), | ||
outlined( | ||
buttonName: 'OutlinedButton', | ||
constructorName: 'OutlinedButton', | ||
priority: convertToOtherButtonPriority, | ||
typeChecker: TypeChecker.fromName( | ||
'OutlinedButton', | ||
packageName: 'flutter', | ||
), | ||
), | ||
text( | ||
buttonName: 'TextButton', | ||
constructorName: 'TextButton', | ||
priority: convertToOtherButtonPriority, | ||
typeChecker: TypeChecker.fromName( | ||
'TextButton', | ||
packageName: 'flutter', | ||
), | ||
); | ||
|
||
const MaterialButtonType({ | ||
required this.buttonName, | ||
required this.constructorName, | ||
required this.priority, | ||
required this.typeChecker, | ||
}); | ||
final String buttonName; | ||
final String constructorName; | ||
final int priority; | ||
final TypeChecker typeChecker; | ||
} | ||
|
||
TypeChecker getBaseType({ | ||
required MaterialButtonType? exclude, | ||
}) { | ||
return TypeChecker.any( | ||
MaterialButtonType.values | ||
.where((e) => e != exclude) | ||
.map((e) => e.typeChecker), | ||
); | ||
} | ||
|
||
final filledButtonType = TypeChecker.any([ | ||
MaterialButtonType.filled.typeChecker, | ||
MaterialButtonType.filledTonal.typeChecker, | ||
]); | ||
|
||
class ConvertToOtherButton extends DartAssist { | ||
ConvertToOtherButton({ | ||
required this.targetType, | ||
}); | ||
final MaterialButtonType targetType; | ||
late final baseType = getBaseType( | ||
exclude: targetType != MaterialButtonType.filled ? targetType : null, | ||
); | ||
|
||
@override | ||
void run( | ||
CustomLintResolver resolver, | ||
ChangeReporter reporter, | ||
CustomLintContext context, | ||
SourceRange target, | ||
) { | ||
context.registry.addInstanceCreationExpression((node) { | ||
// Select from "new" to the opening bracket | ||
if (!target.intersects(node.constructorName.sourceRange)) return; | ||
|
||
final createdType = node.constructorName.type.type; | ||
if (createdType == null || !baseType.isExactlyType(createdType)) { | ||
return; | ||
} | ||
|
||
final simpleIdentifier = node.constructorName.name; | ||
final isFilledButton = filledButtonType.isExactlyType(createdType); | ||
final isTonal = | ||
simpleIdentifier != null && simpleIdentifier.name == 'tonal'; | ||
|
||
if (isFilledButton) { | ||
if (isTonal) { | ||
if (targetType == MaterialButtonType.filledTonal) return; | ||
} else { | ||
if (targetType == MaterialButtonType.filled) return; | ||
} | ||
} | ||
|
||
final changeBuilder = reporter.createChangeBuilder( | ||
message: 'Convert to ${targetType.buttonName}', | ||
priority: targetType.priority, | ||
); | ||
|
||
changeBuilder.addDartFileEdit( | ||
(builder) { | ||
builder.addSimpleReplacement( | ||
node.constructorName.sourceRange, | ||
targetType.constructorName, | ||
); | ||
}, | ||
); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: material_button_assist | ||
description: A starting point for Dart libraries or applications. | ||
version: 1.0.0 | ||
repository: https://github.com/K9i-0/material_widget_lint | ||
|
||
environment: | ||
sdk: ">=2.17.0 <3.0.0" | ||
|
||
dependencies: | ||
custom_lint_builder: ^0.3.4 | ||
analyzer: ^5.7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters