优化示例代码规范

This commit is contained in:
toly
2021-08-18 14:15:44 +08:00
parent 007b074c4e
commit 8a5a57f5ac
12 changed files with 70 additions and 54 deletions

View File

@@ -20,7 +20,7 @@ import 'package:flutter/material.dart';
class CustomText extends StatelessWidget {
@override
Widget build(BuildContext context) {
var style = TextStyle(
TextStyle style = const TextStyle(
color: Colors.blue,
fontSize: 20,
fontWeight: FontWeight.bold,

View File

@@ -15,7 +15,7 @@ import 'package:flutter/material.dart';
class ShadowText extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Text(
return const Text(
"张风捷特烈",
style: TextStyle(
fontSize: 50,

View File

@@ -18,7 +18,7 @@ import 'package:flutter/material.dart';
class DecorationText extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Text(
return const Text(
"19940328",
style: TextStyle(
fontSize: 50,

View File

@@ -19,13 +19,13 @@ class TextAlignText extends StatelessWidget {
spacing: 10,
runSpacing: 10,
children: TextAlign.values
.map((e) => Container(
.map((TextAlign textAlign) => Container(
width: 120,
color: Colors.cyanAccent.withAlpha(33),
height: 120 * 0.618,
child: Text(
" 张风捷特烈 toly " * 3,
textAlign: e,
textAlign: textAlign,
),
))
.toList(),

View File

@@ -20,13 +20,13 @@ class TextDirectionText extends StatelessWidget {
spacing: 40,
runSpacing: 10,
children: TextDirection.values
.map((e) => Container(
.map((TextDirection direction) => Container(
width: 120,
color: Colors.cyanAccent.withAlpha(33),
height: 120 * 0.618,
child: Text(
" 张风捷特烈 toly " * 10,
textDirection: e,
textDirection: direction,
maxLines: 3,
overflow: TextOverflow.ellipsis,
),

View File

@@ -20,14 +20,16 @@ class SoftWrapText extends StatelessWidget {
spacing: 10,
runSpacing: 10,
children: TextOverflow.values
.map((e) => Container(
width: 150,
color: Colors.cyanAccent.withAlpha(33),
height: 150 * 0.618 * 0.618,
child: Text(" 张风捷特烈 toly " * 5,
overflow: e,
softWrap: false),
))
.map((TextOverflow textOverflow) => Container(
width: 150,
color: Colors.cyanAccent.withAlpha(33),
height: 150 * 0.618 * 0.618,
child: Text(
" 张风捷特烈 toly " * 5,
overflow: textOverflow,
softWrap: false,
),
))
.toList(),
);
}

View File

@@ -13,8 +13,8 @@ import 'package:flutter/material.dart';
class TextThemeDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
var queryData = Theme.of(context).textTheme;
var styles = {
TextTheme queryData = Theme.of(context).textTheme;
Map<String, TextStyle> styles = {
"headline: ": queryData.headline,
"title: ": queryData.title,
"subhead: ": queryData.subhead,
@@ -32,32 +32,34 @@ class TextThemeDemo extends StatelessWidget {
return Container(
child: Column(
children: styles.keys.map((e) => buildItem(e, styles[e])).toList(),
children: styles.keys
.map((String styleInfo) => buildItem(styleInfo, styles[styleInfo]))
.toList(),
),
);
}
Widget buildItem(String e, TextStyle style) => Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
e,
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
Text(
Widget buildItem(String styleInfo, TextStyle style) => Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
styleInfo,
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
Text(
"@toly",
style: style,
)
],
),
),
Divider(
height: 1,
)
],
const Divider(
height: 1,
)
],
);
}

View File

@@ -16,12 +16,15 @@ class CustomTheme extends StatelessWidget {
Widget build(BuildContext context) {
return Theme(
data: ThemeData(
cardTheme: CardTheme(color: Colors.red, elevation: 4),
dividerTheme: DividerThemeData(
color: Colors.blue,
thickness: 2
cardTheme: const CardTheme(
color: Colors.red,
elevation: 4,
),
sliderTheme: SliderThemeData(
dividerTheme: const DividerThemeData(
color: Colors.blue,
thickness: 2,
),
sliderTheme: const SliderThemeData(
thumbColor: Colors.red,
activeTrackColor: Colors.green,
inactiveTrackColor: Colors.grey,
@@ -37,9 +40,13 @@ class CustomTheme extends StatelessWidget {
),
),
Container(
width: 150,
child: Slider(value: 0.8, onChanged: (v) => {})),
Container( width: 150,child: Divider())
width: 150,
child: Slider(value: 0.8, onChanged: null),
),
Container(
width: 150,
child: const Divider(),
)
]));
}
}

View File

@@ -16,9 +16,12 @@ class TitleDemo extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
child: Title(
title: '张风捷特烈',
color: Color(0xFF9C27B0),
child: Center(child: Text('应用菜单栏中该页的名称为: 张风捷特烈'))),
title: '张风捷特烈',
color: const Color(0xFF9C27B0),
child: const Center(
child: Text('应用菜单栏中该页的名称为: 张风捷特烈'),
),
),
);
}
}

View File

@@ -20,15 +20,15 @@ class CustomToggleButtons extends StatefulWidget {
}
class _CustomToggleButtonsState extends State<CustomToggleButtons> {
var _isSelected = [true, false, false];
List<bool> _isSelected = [true, false, false];
@override
Widget build(BuildContext context) {
return ToggleButtons(
children: <Widget>[
Icon(Icons.skip_previous),
Icon(Icons.pause),
Icon(Icons.skip_next),
children: const <Widget>[
Icon(Icons.skip_previous),
Icon(Icons.pause),
Icon(Icons.skip_next),
],
borderWidth: 1,
borderRadius: BorderRadius.circular(10),

View File

@@ -22,11 +22,12 @@ class ColorToggleButtons extends StatefulWidget {
}
class _ColorToggleButtonsState extends State<ColorToggleButtons> {
var _isSelected = [true, false, false];
List<bool> _isSelected = [true, false, false];
@override
Widget build(BuildContext context) {
return ToggleButtons(
children: <Widget>[
children: const <Widget>[
Icon(Icons.skip_previous),
Icon(Icons.pause),
Icon(Icons.skip_next),

View File

@@ -17,11 +17,12 @@ class ProToggleButtons extends StatefulWidget {
}
class _ProToggleButtonsState extends State<ProToggleButtons> {
var _isSelected = [false, false, false];
List<bool> _isSelected = [false, false, false];
@override
Widget build(BuildContext context) {
return ToggleButtons(
children: <Widget>[
children: const <Widget>[
Icon(Icons.skip_previous),
Icon(Icons.pause),
Icon(Icons.skip_next),