Skip to content

Commit 8e87c60

Browse files
committed
add hint
1 parent 6394495 commit 8e87c60

File tree

137 files changed

+3098
-2975
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+3098
-2975
lines changed

analysis_options.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
analyzer:
4+
errors:
5+
mixin_inherits_from_not_object: ignore
6+
7+
linter:
8+
rules:
9+
library_private_types_in_public_api: false
10+
constant_identifier_names: false
11+
library_prefixes: false

lib/main.dart

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:flutter/foundation.dart';
12
import 'package:flutter/material.dart';
23
import 'package:gsy_flutter_demo/widget/align_demo_page.dart'
34
deferred as align_demo_page;
@@ -213,9 +214,11 @@ import 'package:gsy_flutter_demo/widget/pageview_in_pageview_demo_page.dart'
213214

214215
import 'package:window_location_href/window_location_href.dart';
215216

216-
void main() => runApp(MyApp());
217+
void main() => runApp(const MyApp());
217218

218219
class MyApp extends StatelessWidget {
220+
const MyApp({super.key});
221+
219222
// This widget is the root of your application.
220223
@override
221224
Widget build(BuildContext context) {
@@ -224,34 +227,36 @@ class MyApp extends StatelessWidget {
224227
theme: ThemeData(
225228
useMaterial3: false,
226229
primarySwatch: Colors.blue,
227-
textButtonTheme: TextButtonThemeData(
230+
textButtonTheme: const TextButtonThemeData(
228231
// 去掉 TextButton 的水波纹效果
229232
style: ButtonStyle(splashFactory: NoSplash.splashFactory),
230233
),
231234
),
232-
home: MyHomePage(title: 'GSY Flutter Demo'),
235+
home: const MyHomePage(title: 'GSY Flutter Demo'),
233236
routes: routers,
234237
);
235238
}
236239
}
237240

238241
class MyHomePage extends StatefulWidget {
239-
MyHomePage({Key? key, this.title}) : super(key: key);
242+
const MyHomePage({super.key, this.title});
240243

241244
final String? title;
242245

243246
@override
244-
_MyHomePageState createState() => _MyHomePageState();
247+
MyHomePageState createState() => MyHomePageState();
245248
}
246249

247-
class _MyHomePageState extends State<MyHomePage> {
250+
class MyHomePageState extends State<MyHomePage> {
248251
@override
249252
void initState() {
250253
//loadLibrary();
251254
super.initState();
252-
print("get enum value with 2.15 ${Cat.white.name}");
253-
print("get enum value with 2.15 ${Cat.values.byName("black")}");
254-
print("get enum value with 2.17 ${Cat.white.value} ${Cat.white}");
255+
if (kDebugMode) {
256+
print("get enum value with 2.15 ${Cat.white.name}");
257+
print("get enum value with 2.15 ${Cat.values.byName("black")}");
258+
print("get enum value with 2.17 ${Cat.white.value} ${Cat.white}");
259+
}
255260

256261
final href = getHref();
257262
int? index = href?.indexOf("#");
@@ -276,25 +281,23 @@ class _MyHomePageState extends State<MyHomePage> {
276281
appBar: AppBar(
277282
title: Text(widget.title!),
278283
),
279-
body: new Container(
280-
child: new ListView.builder(
281-
itemBuilder: (context, index) {
282-
return new InkWell(
283-
onTap: () {
284-
Navigator.of(context).pushNamed(routeLists[index]);
285-
},
286-
child: new Card(
287-
child: new Container(
288-
alignment: Alignment.centerLeft,
289-
margin: EdgeInsets.symmetric(horizontal: 10),
290-
height: 50,
291-
child: new Text(routers.keys.toList()[index]),
292-
),
284+
body: ListView.builder(
285+
itemBuilder: (context, index) {
286+
return InkWell(
287+
onTap: () {
288+
Navigator.of(context).pushNamed(routeLists[index]);
289+
},
290+
child: Card(
291+
child: Container(
292+
alignment: Alignment.centerLeft,
293+
margin: const EdgeInsets.symmetric(horizontal: 10),
294+
height: 50,
295+
child: Text(routers.keys.toList()[index]),
293296
),
294-
);
295-
},
296-
itemCount: routers.length,
297-
),
297+
),
298+
);
299+
},
300+
itemCount: routers.length,
298301
), // This trailing comma makes auto-formatting nicer for build methods.
299302
);
300303
}
@@ -307,7 +310,7 @@ class ContainerAsyncRouterPage extends StatelessWidget {
307310
///稍后更新文章到掘金
308311
final WidgetBuilder child;
309312

310-
ContainerAsyncRouterPage(this.libraryFuture, this.child);
313+
const ContainerAsyncRouterPage(this.libraryFuture, this.child, {super.key});
311314

312315
@override
313316
Widget build(BuildContext context) {
@@ -322,7 +325,7 @@ class ContainerAsyncRouterPage extends StatelessWidget {
322325
alignment: Alignment.center,
323326
child: Text(
324327
'Error: ${s.error}',
325-
style: TextStyle(color: Colors.red),
328+
style: const TextStyle(color: Colors.red),
326329
),
327330
),
328331
);
@@ -333,7 +336,7 @@ class ContainerAsyncRouterPage extends StatelessWidget {
333336
appBar: AppBar(),
334337
body: Container(
335338
alignment: Alignment.center,
336-
child: CircularProgressIndicator(),
339+
child: const CircularProgressIndicator(),
337340
),
338341
);
339342
});
@@ -940,6 +943,8 @@ extension CatExtension on Cat {
940943
// }
941944

942945
void talk() {
943-
print('meow');
946+
if (kDebugMode) {
947+
print('meow');
948+
}
944949
}
945950
}

lib/widget/align_demo_page.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@ import 'dart:math' as math;
22
import 'package:flutter/material.dart';
33

44
class AlignDemoPage extends StatefulWidget {
5+
const AlignDemoPage({super.key});
6+
57
@override
6-
_AlignDemoPageState createState() => _AlignDemoPageState();
8+
AlignDemoPageState createState() => AlignDemoPageState();
79
}
810

9-
class _AlignDemoPageState extends State<AlignDemoPage>
11+
class AlignDemoPageState extends State<AlignDemoPage>
1012
with SingleTickerProviderStateMixin {
1113
getAlign(x) {
1214
return Align(
13-
child: new Container(
15+
alignment: Alignment(math.cos(x * math.pi), math.sin(x * math.pi)),
16+
child: Container(
1417
height: 20,
1518
width: 20,
16-
decoration: BoxDecoration(
19+
decoration: const BoxDecoration(
1720
color: Colors.green,
1821
borderRadius: BorderRadius.all(Radius.circular(10))),
1922
),
20-
alignment: Alignment(math.cos(x * math.pi), math.sin(x * math.pi)),
2123
);
2224
}
2325

@@ -26,11 +28,11 @@ class _AlignDemoPageState extends State<AlignDemoPage>
2628
int size = 20;
2729
return Scaffold(
2830
appBar: AppBar(
29-
title: new Text("AlignDemoPage"),
31+
title: const Text("AlignDemoPage"),
3032
),
31-
body: new Container(
32-
alignment: Alignment(0, 0),
33-
child: Container(
33+
body: Container(
34+
alignment: const Alignment(0, 0),
35+
child: SizedBox(
3436
height: MediaQuery.sizeOf(context).width,
3537
width: MediaQuery.sizeOf(context).width,
3638
child: Stack(

lib/widget/anim_bg_demo_page.dart

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,36 @@ import 'package:supercharged/supercharged.dart';
66
enum _ColorTween { color1, color2 }
77

88
class AnimBgDemoPage extends StatelessWidget {
9+
const AnimBgDemoPage({super.key});
10+
911
@override
1012
Widget build(BuildContext context) {
1113
return Scaffold(
1214
appBar: AppBar(
13-
title: new Text("AnimBgDemoPage"),
15+
title: const Text("AnimBgDemoPage"),
1416
),
1517
body: Stack(
1618
children: <Widget>[
17-
Positioned.fill(child: AnimatedBackground()),
18-
onBottom(AnimatedWave(
19+
const Positioned.fill(child: AnimatedBackground()),
20+
onBottom(const AnimatedWave(
1921
height: 180,
2022
speed: 1.0,
2123
)),
22-
onBottom(AnimatedWave(
24+
onBottom(const AnimatedWave(
2325
height: 120,
2426
speed: 0.9,
2527
offset: pi,
2628
)),
27-
onBottom(AnimatedWave(
29+
onBottom(const AnimatedWave(
2830
height: 220,
2931
speed: 1.2,
3032
offset: pi / 2,
3133
)),
32-
Positioned.fill(
33-
child: new Center(
34-
child: new Text(
34+
const Positioned.fill(
35+
child: Center(
36+
child: Text(
3537
"GSY Flutter Demo",
36-
style: new TextStyle(
38+
style: TextStyle(
3739
fontSize: 30,
3840
fontWeight: FontWeight.bold,
3941
color: Colors.white),
@@ -57,12 +59,12 @@ class AnimatedWave extends StatelessWidget {
5759
final double? speed;
5860
final double offset;
5961

60-
AnimatedWave({this.height, this.speed, this.offset = 0.0});
62+
const AnimatedWave({super.key, this.height, this.speed, this.offset = 0.0});
6163

6264
@override
6365
Widget build(BuildContext context) {
6466
return LayoutBuilder(builder: (context, constraints) {
65-
return Container(
67+
return SizedBox(
6668
height: height,
6769
width: constraints.biggest.width,
6870
child: LoopAnimationBuilder<double>(
@@ -112,17 +114,19 @@ class CurvePainter extends CustomPainter {
112114
}
113115

114116
class AnimatedBackground extends StatelessWidget {
117+
const AnimatedBackground({super.key});
118+
115119
@override
116120
Widget build(BuildContext context) {
117121
final tween = MovieTween()
118122
..tween(
119123
_ColorTween.color1,
120-
Color(0xffD38312).tweenTo(Colors.lightBlue.shade900),
124+
const Color(0xffD38312).tweenTo(Colors.lightBlue.shade900),
121125
duration: 3.seconds,
122126
)
123127
..tween(
124128
_ColorTween.color2,
125-
Color(0xffA83279).tweenTo(Colors.blue.shade600),
129+
const Color(0xffA83279).tweenTo(Colors.blue.shade600),
126130
duration: 3.seconds,
127131
);
128132

lib/widget/anim_bubble_gum.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import 'package:flutter/material.dart';
99
/// https://codepen.io/rx-labz/pen/xxwdGaM?__cf_chl_jschl_tk__=830b2fd03dd1ccb9ac8d7c1fdbdee39e71fc2e7c-1587971334-0-AQ6h_JKRflUPLJcJhlH7eT841oCDgD5EttuC0cq9I50PQHwBtecDMdA9H-_a9FitSk4HQwlPO3dvvYn83act0FI6ufSlRL7MCB-gJVkKQov2i-AVA92X3KFwD93JOfog1LMy9yTdUyNb1zr43ZgC2X-cg0IsMGPr6U54kAb40AQgoK-KbYc9-KYWUIFqFy8pShOZIfn23-0lInSjKlJ3p8rnLXp84p7rhdTNrQU0pWPKNiDkuuthEaqzi9THfk4-iTrZ3CJ6wU0t81T9GyKwIT5VthFlnuPyNqIKseggtyxBxgZJ4W4ec6FmQoFp7bYAQF9rFb3D5L_3juEL-262JH_TP20ojcgjb30pvNnHyTfh
1010
1111
class AnimBubbleGumDemoPage extends StatelessWidget {
12+
const AnimBubbleGumDemoPage({super.key});
13+
1214
@override
1315
Widget build(BuildContext context) {
1416
return Scaffold(
1517
appBar: AppBar(
16-
title: Text("AnimBubbleGumDemoPage"),
18+
title: const Text("AnimBubbleGumDemoPage"),
1719
),
18-
body: Container(color: Colors.pink[200], child: AnimBubbleGum()),
20+
body: Container(color: Colors.pink[200], child: const AnimBubbleGum()),
1921
);
2022
}
2123
}
@@ -40,18 +42,20 @@ class Circle {
4042
}
4143

4244
class AnimBubbleGum extends StatefulWidget {
45+
const AnimBubbleGum({super.key});
46+
4347
@override
44-
_AnimBubbleGumState createState() => _AnimBubbleGumState();
48+
AnimBubbleGumState createState() => AnimBubbleGumState();
4549
}
4650

47-
class _AnimBubbleGumState extends State<AnimBubbleGum> {
51+
class AnimBubbleGumState extends State<AnimBubbleGum> {
4852
late Timer timer;
4953

5054
final circles = <Circle>[];
5155

5256
late Size size;
5357

54-
Offset force = Offset(1, 1);
58+
Offset force = const Offset(1, 1);
5559

5660
HSLColor hslColor = HSLColor.fromColor(Colors.pink[100]!);
5761

@@ -70,7 +74,7 @@ class _AnimBubbleGumState extends State<AnimBubbleGum> {
7074
timer = Timer.periodic(
7175
frequency,
7276
(t) {
73-
if (circles.isEmpty)
77+
if (circles.isEmpty) {
7478
_circleStreamer.add(
7579
circles
7680
..add(
@@ -81,6 +85,7 @@ class _AnimBubbleGumState extends State<AnimBubbleGum> {
8185
),
8286
),
8387
);
88+
}
8489
int count = 0;
8590
while (count < 29) {
8691
final p = // newPoint
@@ -118,7 +123,7 @@ class _AnimBubbleGumState extends State<AnimBubbleGum> {
118123
Widget build(BuildContext context) => Stack(
119124
children: [
120125
StreamBuilder<List<Circle>>(
121-
initialData: [],
126+
initialData: const [],
122127
stream: _circle$.map(
123128
(event) => event.length > numCircles
124129
? event
@@ -164,11 +169,12 @@ class Painter extends CustomPainter {
164169
c.offset! - Offset(0, c.radius),
165170
c.radius,
166171
[
167-
Color(0x53ffffff),
172+
const Color(0x53ffffff),
168173
Colors.transparent,
169174
],
170175
);
171176
}
177+
// ignore: empty_catches
172178
} catch (e) {}
173179
//too heavy for mobile web rendering
174180

0 commit comments

Comments
 (0)