Skip to content

Commit 0701709

Browse files
committed
👌 DCM Suggestion Changes
1 parent 83aa3b9 commit 0701709

File tree

8 files changed

+126
-145
lines changed

8 files changed

+126
-145
lines changed

.github/workflows/code-quality.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ name: code-quality
33
on:
44
pull_request:
55
branches: [main]
6-
push:
7-
branches: [main]
86

97
jobs:
108
check:

analysis_options.yaml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
# The following line activates a set of recommended lints for Flutter apps,
99
# packages, and plugins designed to encourage good coding practices.
10-
include: package:flutter_lints/flutter.yaml
10+
include: package:dart_code_metrics_presets/all.yaml
1111

1212
dart_code_metrics:
1313
monorepo: true
1414
extends:
15-
- package:dart_code_metrics_presets/all.yaml
1615
- recommended
1716
metrics:
1817
cyclomatic-complexity: 20
@@ -40,21 +39,3 @@ dart_code_metrics:
4039
deprecated-annotations-cost: 37
4140
file-nullsafety-migration-cost: 41
4241
unit-type: "INR"
43-
44-
linter:
45-
# The lint rules applied to this project can be customized in the
46-
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
47-
# included above or to enable additional rules. A list of all available lints
48-
# and their documentation is published at https://dart.dev/lints.
49-
#
50-
# Instead of disabling a lint rule for the entire project in the
51-
# section below, it can also be suppressed for a single line of code
52-
# or a specific dart file by using the `// ignore: name_of_lint` and
53-
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
54-
# producing the lint.
55-
rules:
56-
# avoid_print: false # Uncomment to disable the `avoid_print` rule
57-
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
58-
59-
# Additional information about this file can be found at
60-
# https://dart.dev/guides/language/analysis-options

lib/main.dart

Lines changed: 2 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,7 @@
11
import 'package:flutter/material.dart';
22

3+
import 'my_app.dart';
4+
35
void main() {
46
runApp(const MyApp());
57
}
6-
7-
class MyApp extends StatelessWidget {
8-
const MyApp({super.key});
9-
10-
// This widget is the root of your application.
11-
@override
12-
Widget build(BuildContext context) {
13-
return MaterialApp(
14-
title: 'Flutter Demo',
15-
theme: ThemeData(
16-
// This is the theme of your application.
17-
//
18-
// TRY THIS: Try running your application with "flutter run". You'll see
19-
// the application has a purple toolbar. Then, without quitting the app,
20-
// try changing the seedColor in the colorScheme below to Colors.green
21-
// and then invoke "hot reload" (save your changes or press the "hot
22-
// reload" button in a Flutter-supported IDE, or press "r" if you used
23-
// the command line to start the app).
24-
//
25-
// Notice that the counter didn't reset back to zero; the application
26-
// state is not lost during the reload. To reset the state, use hot
27-
// restart instead.
28-
//
29-
// This works for code too, not just values: Most code changes can be
30-
// tested with just a hot reload.
31-
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
32-
useMaterial3: true,
33-
),
34-
home: const MyHomePage(title: 'Flutter Demo Home Page'),
35-
);
36-
}
37-
}
38-
39-
class MyHomePage extends StatefulWidget {
40-
const MyHomePage({super.key, required this.title});
41-
42-
// This widget is the home page of your application. It is stateful, meaning
43-
// that it has a State object (defined below) that contains fields that affect
44-
// how it looks.
45-
46-
// This class is the configuration for the state. It holds the values (in this
47-
// case the title) provided by the parent (in this case the App widget) and
48-
// used by the build method of the State. Fields in a Widget subclass are
49-
// always marked "final".
50-
51-
final String title;
52-
53-
@override
54-
State<MyHomePage> createState() => _MyHomePageState();
55-
}
56-
57-
class _MyHomePageState extends State<MyHomePage> {
58-
int _counter = 0;
59-
60-
void _incrementCounter() {
61-
setState(() {
62-
// This call to setState tells the Flutter framework that something has
63-
// changed in this State, which causes it to rerun the build method below
64-
// so that the display can reflect the updated values. If we changed
65-
// _counter without calling setState(), then the build method would not be
66-
// called again, and so nothing would appear to happen.
67-
_counter++;
68-
});
69-
}
70-
71-
@override
72-
Widget build(BuildContext context) {
73-
// This method is rerun every time setState is called, for instance as done
74-
// by the _incrementCounter method above.
75-
//
76-
// The Flutter framework has been optimized to make rerunning build methods
77-
// fast, so that you can just rebuild anything that needs updating rather
78-
// than having to individually change instances of widgets.
79-
return Scaffold(
80-
appBar: AppBar(
81-
// TRY THIS: Try changing the color here to a specific color (to
82-
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
83-
// change color while the other colors stay the same.
84-
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
85-
// Here we take the value from the MyHomePage object that was created by
86-
// the App.build method, and use it to set our appbar title.
87-
title: Text(widget.title),
88-
),
89-
body: Center(
90-
// Center is a layout widget. It takes a single child and positions it
91-
// in the middle of the parent.
92-
child: Column(
93-
// Column is also a layout widget. It takes a list of children and
94-
// arranges them vertically. By default, it sizes itself to fit its
95-
// children horizontally, and tries to be as tall as its parent.
96-
//
97-
// Column has various properties to control how it sizes itself and
98-
// how it positions its children. Here we use mainAxisAlignment to
99-
// center the children vertically; the main axis here is the vertical
100-
// axis because Columns are vertical (the cross axis would be
101-
// horizontal).
102-
//
103-
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
104-
// action in the IDE, or press "p" in the console), to see the
105-
// wireframe for each widget.
106-
mainAxisAlignment: MainAxisAlignment.center,
107-
children: <Widget>[
108-
const Text(
109-
'You have pushed the button this many times:',
110-
),
111-
Text(
112-
'$_counter',
113-
style: Theme.of(context).textTheme.headlineMedium,
114-
),
115-
],
116-
),
117-
),
118-
floatingActionButton: FloatingActionButton(
119-
onPressed: _incrementCounter,
120-
tooltip: 'Increment',
121-
child: const Icon(Icons.add),
122-
), // This trailing comma makes auto-formatting nicer for build methods.
123-
);
124-
}
125-
}

lib/my_app.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import 'package:flutter/material.dart';
2+
3+
import 'my_home_page.dart';
4+
import 'values/app_strings.dart';
5+
6+
class MyApp extends StatelessWidget {
7+
const MyApp({super.key});
8+
9+
// This widget is the root of your application.
10+
@override
11+
Widget build(BuildContext context) {
12+
return MaterialApp(
13+
home: const MyHomePage(),
14+
title: AppStrings.appTitle,
15+
theme: ThemeData(
16+
useMaterial3: true,
17+
// This is the theme of your application.
18+
//
19+
// TRY THIS: Try running your application with "flutter run". You'll see
20+
// the application has a purple toolbar. Then, without quitting the app,
21+
// try changing the seedColor in the colorScheme below to Colors.green
22+
// and then invoke "hot reload" (save your changes or press the "hot
23+
// reload" button in a Flutter-supported IDE, or press "r" if you used
24+
// the command line to start the app).
25+
//
26+
// Notice that the counter didn't reset back to zero; the application
27+
// state is not lost during the reload. To reset the state, use hot
28+
// restart instead.
29+
//
30+
// This works for code too, not just values: Most code changes can be
31+
// tested with just a hot reload.
32+
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
33+
),
34+
);
35+
}
36+
}

lib/my_home_page.dart

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import 'package:flutter/material.dart';
2+
3+
import 'values/app_strings.dart';
4+
5+
class MyHomePage extends StatefulWidget {
6+
const MyHomePage({super.key});
7+
8+
@override
9+
State<MyHomePage> createState() => _MyHomePageState();
10+
}
11+
12+
class _MyHomePageState extends State<MyHomePage> {
13+
int _counter = 0;
14+
15+
void _handleCounterIncrement() {
16+
setState(() {
17+
// This call to setState tells the Flutter framework that something has
18+
// changed in this State, which causes it to rerun the build method below
19+
// so that the display can reflect the updated values. If we changed
20+
// _counter without calling setState(), then the build method would not be
21+
// called again, and so nothing would appear to happen.
22+
_counter += 1;
23+
});
24+
}
25+
26+
@override
27+
Widget build(BuildContext context) {
28+
// This method is rerun every time setState is called, for instance as done
29+
// by the _incrementCounter method above.
30+
//
31+
// The Flutter framework has been optimized to make rerunning build methods
32+
// fast, so that you can just rebuild anything that needs updating rather
33+
// than having to individually change instances of widgets.
34+
return Scaffold(
35+
appBar: AppBar(
36+
// Here we take the value from the MyHomePage object that was created by
37+
// the App.build method, and use it to set our appbar title.
38+
title: Text(AppStrings.appTitle),
39+
// TRY THIS: Try changing the color here to a specific color (to
40+
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
41+
// change color while the other colors stay the same.
42+
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
43+
),
44+
body: Center(
45+
// Center is a layout widget. It takes a single child and positions it
46+
// in the middle of the parent.
47+
child: Column(
48+
// Column is also a layout widget. It takes a list of children and
49+
// arranges them vertically. By default, it sizes itself to fit its
50+
// children horizontally, and tries to be as tall as its parent.
51+
//
52+
// Column has various properties to control how it sizes itself and
53+
// how it positions its children. Here we use mainAxisAlignment to
54+
// center the children vertically; the main axis here is the vertical
55+
// axis because Columns are vertical (the cross axis would be
56+
// horizontal).
57+
//
58+
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
59+
// action in the IDE, or press "p" in the console), to see the
60+
// wireframe for each widget.
61+
mainAxisAlignment: MainAxisAlignment.center,
62+
children: [
63+
const Text(AppStrings.pushedThisManyTimes),
64+
Text(
65+
_counter.toString(),
66+
style: Theme.of(context).textTheme.headlineMedium,
67+
),
68+
],
69+
),
70+
),
71+
floatingActionButton: FloatingActionButton(
72+
child: const Icon(Icons.add),
73+
tooltip: AppStrings.increment,
74+
heroTag: const ValueKey('Add'),
75+
onPressed: _handleCounterIncrement,
76+
), // This trailing comma makes auto-formatting nicer for build methods.
77+
);
78+
}
79+
}

lib/values/app_strings.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class AppStrings {
2+
static const increment = 'Increment';
3+
static const pushedThisManyTimes = 'You have pushed the button this many times:';
4+
static const appTitle = 'DCM Demo';
5+
6+
const AppStrings._();
7+
}

pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ dev_dependencies:
4545
# activated in the `analysis_options.yaml` file located at the root of your
4646
# package. See that file for information about deactivating specific lint
4747
# rules and activating additional ones.
48-
flutter_lints: ^2.0.0
4948
dart_code_metrics_presets: ^2.12.0
5049

5150
# For information on the generic Dart part of this file, see the

test/widget_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
// gestures. You can also use WidgetTester to find child widgets in the widget
66
// tree, read text, and verify that the values of widget properties are correct.
77

8+
import 'package:counter_dcm/my_app.dart';
89
import 'package:flutter/material.dart';
910
import 'package:flutter_test/flutter_test.dart';
1011

11-
import 'package:counter_dcm/main.dart';
12-
1312
void main() {
1413
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
1514
// Build our app and trigger a frame.

0 commit comments

Comments
 (0)