瀏覽代碼

null safety

zhaoyadi 3 年之前
父節點
當前提交
d14dadad64
共有 4 個文件被更改,包括 152 次插入61 次删除
  1. 52 14
      example/lib/four_page.dart
  2. 91 39
      example/lib/one_page.dart
  3. 4 2
      example/lib/three_page.dart
  4. 5 6
      example/lib/two_page.dart

+ 52 - 14
example/lib/four_page.dart

@@ -7,7 +7,7 @@ class FourPage extends StatefulWidget {
 }
 
 class FourPageState extends State<FourPage> {
-  List<CheckTestModel> _mdoelList;
+  late List<CheckTestModel> _mdoelList;
 
   @override
   void initState() {
@@ -33,7 +33,11 @@ class FourPageState extends State<FourPage> {
             color: Colors.transparent,
             child: Text(
               '确定',
-              style: TextStyle(fontSize: 14, height: 1, color: Color(0xFF5F87F0), fontWeight: FontWeight.w600),
+              style: TextStyle(
+                  fontSize: 14,
+                  height: 1,
+                  color: Color(0xFF5F87F0),
+                  fontWeight: FontWeight.w600),
             ),
           ),
         ),
@@ -83,7 +87,11 @@ class HeaderView extends StatelessWidget {
         children: [
           Text(
             "全部家长",
-            style: TextStyle(color: Colors.black, fontSize: 16, height: 22 / 16, fontWeight: FontWeight.w500),
+            style: TextStyle(
+                color: Colors.black,
+                fontSize: 16,
+                height: 22 / 16,
+                fontWeight: FontWeight.w500),
           ),
           CheckedIcon(WH: 23)
         ],
@@ -99,7 +107,8 @@ class FirstCell extends StatelessWidget {
       padding: EdgeInsets.only(top: 25, bottom: 22, left: 12, right: 18),
       decoration: BoxDecoration(
         color: Colors.white,
-        borderRadius: BorderRadius.only(topLeft: Radius.circular(10), topRight: Radius.circular(10)),
+        borderRadius: BorderRadius.only(
+            topLeft: Radius.circular(10), topRight: Radius.circular(10)),
       ),
       child: Row(
         mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -109,12 +118,20 @@ class FirstCell extends StatelessWidget {
             children: [
               Text(
                 "指定家长(93个家长)",
-                style: TextStyle(color: Colors.black, fontSize: 16, height: 22 / 16, fontWeight: FontWeight.w500),
+                style: TextStyle(
+                    color: Colors.black,
+                    fontSize: 16,
+                    height: 22 / 16,
+                    fontWeight: FontWeight.w500),
               ),
               SizedBox(height: 4),
               Text(
                 "选择家长分享评估报告",
-                style: TextStyle(color: Color(0xFF9C9AAB), fontSize: 12, height: 17 / 12, fontWeight: FontWeight.w400),
+                style: TextStyle(
+                    color: Color(0xFF9C9AAB),
+                    fontSize: 12,
+                    height: 17 / 12,
+                    fontWeight: FontWeight.w400),
               ),
             ],
           ),
@@ -134,7 +151,10 @@ class FirstCell extends StatelessWidget {
 class NormalCell extends StatelessWidget {
   final CheckTestModel model;
 
-  const NormalCell({Key key, this.model}) : super(key: key);
+  const NormalCell({
+    Key? key,
+    required this.model,
+  }) : super(key: key);
 
   @override
   Widget build(BuildContext context) {
@@ -152,7 +172,11 @@ class NormalCell extends StatelessWidget {
           SizedBox(width: 15),
           Text(
             "王小二",
-            style: TextStyle(color: Colors.black, fontSize: 16, height: 22 / 16, fontWeight: FontWeight.w400),
+            style: TextStyle(
+                color: Colors.black,
+                fontSize: 16,
+                height: 22 / 16,
+                fontWeight: FontWeight.w400),
           ),
         ],
       ),
@@ -167,7 +191,8 @@ class LastCell extends StatelessWidget {
       height: 49,
       decoration: BoxDecoration(
         color: Colors.white,
-        borderRadius: BorderRadius.only(bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10)),
+        borderRadius: BorderRadius.only(
+            bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10)),
       ),
     );
   }
@@ -202,7 +227,10 @@ class TrianglePainter extends CustomPainter {
 class DividingLinesView extends StatelessWidget {
   final int index;
 
-  const DividingLinesView({Key key, this.index}) : super(key: key);
+  const DividingLinesView({
+    Key? key,
+    required this.index,
+  }) : super(key: key);
 
   @override
   Widget build(BuildContext context) {
@@ -228,14 +256,19 @@ class DividingLinesView extends StatelessWidget {
 class UncheckedIcon extends StatelessWidget {
   final double WH;
 
-  const UncheckedIcon({Key key, this.WH}) : super(key: key);
+  const UncheckedIcon({
+    Key? key,
+    required this.WH,
+  }) : super(key: key);
 
   @override
   Widget build(BuildContext context) {
     return Container(
       width: WH,
       height: WH,
-      decoration: BoxDecoration(borderRadius: BorderRadius.circular(WH / 2), border: Border.all(color: Color(0xFFD1D1D1), width: 1.3)),
+      decoration: BoxDecoration(
+          borderRadius: BorderRadius.circular(WH / 2),
+          border: Border.all(color: Color(0xFFD1D1D1), width: 1.3)),
     );
   }
 }
@@ -244,14 +277,19 @@ class UncheckedIcon extends StatelessWidget {
 class CheckedIcon extends StatelessWidget {
   final double WH;
 
-  const CheckedIcon({Key key, this.WH}) : super(key: key);
+  const CheckedIcon({
+    Key? key,
+    required this.WH,
+  }) : super(key: key);
 
   @override
   Widget build(BuildContext context) {
     return Container(
       width: WH,
       height: WH,
-      decoration: BoxDecoration(borderRadius: BorderRadius.circular(WH / 2), color: Color(0xFF5F87F0)),
+      decoration: BoxDecoration(
+          borderRadius: BorderRadius.circular(WH / 2),
+          color: Color(0xFF5F87F0)),
       child: Icon(
         Icons.check_rounded,
         color: Colors.white,

+ 91 - 39
example/lib/one_page.dart

@@ -40,13 +40,24 @@ class OnePageState extends State<OnePage> {
 /// titlesList:外面的标题数组
 /// minRadius:最小圆的半径
 /// poorRadius:扩散圆的半径差
-Widget radarMapComponent(List titlesList, double minRadius, double poorRadius, {BuildContext context}) {
+Widget radarMapComponent(
+  List titlesList,
+  double minRadius,
+  double poorRadius, {
+  required BuildContext context,
+}) {
   double maxRadius = minRadius + poorRadius * titlesList.length - 1;
 
   return Container(
-    width: maxRadius*2 + 100,
-    height: maxRadius*2 + 100,
-    child: CustomPaint(size: Size(maxRadius*2 + 100, maxRadius*2 + 100), painter: TolyPainter(titlesList: titlesList, minRadius: minRadius, poorRadius: poorRadius, context: context)),
+    width: maxRadius * 2 + 100,
+    height: maxRadius * 2 + 100,
+    child: CustomPaint(
+        size: Size(maxRadius * 2 + 100, maxRadius * 2 + 100),
+        painter: TolyPainter(
+            titlesList: titlesList,
+            minRadius: minRadius,
+            poorRadius: poorRadius,
+            context: context)),
   );
 }
 
@@ -56,7 +67,12 @@ class TolyPainter extends CustomPainter {
   final double minRadius;
   final double poorRadius;
 
-  TolyPainter({@required this.context, this.titlesList, this.minRadius, this.poorRadius});
+  TolyPainter({
+    required this.context,
+    required this.titlesList,
+    required this.minRadius,
+    required this.poorRadius,
+  });
 
   @override
   void paint(Canvas canvas, Size size) {
@@ -64,7 +80,6 @@ class TolyPainter extends CustomPainter {
 
     canvas.translate(size.width / 2, size.height / 2);
 
-
     //虚线画笔
     Paint dottedLinePaint = Paint()
       ..style = PaintingStyle.stroke
@@ -90,19 +105,21 @@ class TolyPainter extends CustomPainter {
     Path polygonBrushesPath = Path();
 
     //文字画笔
-    TextPainter _textPainter = new TextPainter(textAlign: TextAlign.left, textDirection: TextDirection.ltr);
+    TextPainter _textPainter = new TextPainter(
+        textAlign: TextAlign.left, textDirection: TextDirection.ltr);
 
     final Path path = Path();
     final dottedLinePath = Path();
 
-
-
     //绘制文字
     for (int i = 0; i < titlesList.length; i++) {
-      Size textSize = boundingTextSize(context, titlesList[i], TextStyle(color: Colors.white, fontSize: 9));
+      Size textSize = boundingTextSize(
+          context, titlesList[i], TextStyle(color: Colors.white, fontSize: 9));
       canvas.save(); //与restore配合使用保存当前画布
-      canvas.translate(0.0, -maxRadius -10); //平移画布画点于时钟的12点位置,+30为了调整数字与刻度的间隔
-      _textPainter.text = TextSpan(style: TextStyle(color: Colors.white, fontSize: 9), text: titlesList[i]);
+      canvas.translate(0.0, -maxRadius - 10); //平移画布画点于时钟的12点位置,+30为了调整数字与刻度的间隔
+      _textPainter.text = TextSpan(
+          style: TextStyle(color: Colors.white, fontSize: 9),
+          text: titlesList[i]);
       canvas.rotate(-angleToRadian(360 / titlesList.length * i)); //保持画的文字竖直显示。
       _textPainter.layout();
 
@@ -111,41 +128,48 @@ class TolyPainter extends CustomPainter {
       double radiu = 360 / titlesList.length * i;
 
       if (radiu == 0 || radiu == 1) {
-        _textPainter.paint(canvas, Offset(-_textPainter.width / 2 , -_textPainter.height / 2 - 5));
-      }
-      else if(0 <  radiu && radiu < 180){
+        _textPainter.paint(canvas,
+            Offset(-_textPainter.width / 2, -_textPainter.height / 2 - 5));
+      } else if (0 < radiu && radiu < 180) {
         _textPainter.paint(canvas, Offset(0, -5));
-      }
-      else if(180 <  radiu && radiu < 360){
+      } else if (180 < radiu && radiu < 360) {
         _textPainter.paint(canvas, Offset(-_textPainter.width, -5));
+      } else {
+        _textPainter.paint(canvas,
+            Offset(-_textPainter.width / 2, -_textPainter.height / 2 + 5));
       }
-      else{
-        _textPainter.paint(canvas, Offset(-_textPainter.width / 2, -_textPainter.height / 2 + 5));
-      }
-
 
       canvas.restore(); //画布重置,恢复到控件中心
-      canvas.rotate(angleToRadian(360 / titlesList.length)); //画布旋转一个区间刻度,把文字和刻度对应起来
+      canvas.rotate(
+          angleToRadian(360 / titlesList.length)); //画布旋转一个区间刻度,把文字和刻度对应起来
     }
 
-
-
-
     List<Offset> pointsList = [];
 
     for (int i = 0; i < titlesList.length; i++) {
       path.moveTo(0, 0);
       dottedLinePath.moveTo(0, 0);
       if (i < titlesList.length - 1) {
-        dottedLinePath.addOval(Rect.fromCircle(center: Offset.zero, radius: 30.0 + 18 * i));
+        dottedLinePath.addOval(
+            Rect.fromCircle(center: Offset.zero, radius: 30.0 + 18 * i));
       }
 
       double maxRadius = minRadius + poorRadius * titlesList.length;
-      double x = (30 + 18 * (titlesList.length - 1)) * cos(angleToRadian(360 / titlesList.length * (i + 1) - 90));
-      double y = (30 + 18 * (titlesList.length - 1)) * sin(angleToRadian(360 / titlesList.length * (i + 1) - 90));
+      double x = (30 + 18 * (titlesList.length - 1)) *
+          cos(angleToRadian(360 / titlesList.length * (i + 1) - 90));
+      double y = (30 + 18 * (titlesList.length - 1)) *
+          sin(angleToRadian(360 / titlesList.length * (i + 1) - 90));
 
       path.lineTo(x, y);
-      pointsList.add(Offset(cos(angleToRadian(360 / titlesList.length * (i + 1) - 90)) * maxRadius * (i + 1 > titlesList.length - 1 ? titlesList.length - 2 : i + 1) / titlesList.length, sin(angleToRadian(360 / titlesList.length * (i + 1) - 90)) * maxRadius * (i + 1 > titlesList.length - 1 ? titlesList.length - 1 : i + 1) / titlesList.length));
+      pointsList.add(Offset(
+          cos(angleToRadian(360 / titlesList.length * (i + 1) - 90)) *
+              maxRadius *
+              (i + 1 > titlesList.length - 1 ? titlesList.length - 2 : i + 1) /
+              titlesList.length,
+          sin(angleToRadian(360 / titlesList.length * (i + 1) - 90)) *
+              maxRadius *
+              (i + 1 > titlesList.length - 1 ? titlesList.length - 1 : i + 1) /
+              titlesList.length));
     }
 
     polygonBrushesPath.addPolygon(pointsList, true);
@@ -165,12 +189,22 @@ class TolyPainter extends CustomPainter {
         ..addText((i * 2).toString());
       ParagraphConstraints pc = ParagraphConstraints(width: 50);
       Paragraph paragraph = pb.build()..layout(pc);
-      canvas.drawParagraph(paragraph, Offset((minRadius + poorRadius * i) * (11 + 13 * i) / (minRadius+ poorRadius * i), (minRadius + poorRadius * i) * (11 + 13 * i) / (minRadius + poorRadius * i)));
+      canvas.drawParagraph(
+          paragraph,
+          Offset(
+              (minRadius + poorRadius * i) *
+                  (11 + 13 * i) /
+                  (minRadius + poorRadius * i),
+              (minRadius + poorRadius * i) *
+                  (11 + 13 * i) /
+                  (minRadius + poorRadius * i)));
     }
 
-    DashPainter(span: 4, step: 9, pointWidth: 10).paint(canvas, dottedLinePath, dottedLinePaint);
+    DashPainter(span: 4, step: 9, pointWidth: 10)
+        .paint(canvas, dottedLinePath, dottedLinePaint);
     canvas.drawPath(path, paint);
-    canvas.drawCircle(Offset.zero, minRadius + 18 * (titlesList.length - 1), paint);
+    canvas.drawCircle(
+        Offset.zero, minRadius + 18 * (titlesList.length - 1), paint);
 
     ParagraphBuilder pb = ParagraphBuilder(ParagraphStyle(
       textAlign: TextAlign.left,
@@ -182,14 +216,29 @@ class TolyPainter extends CustomPainter {
       ..addText((titlesList.length * 2).toString());
     ParagraphConstraints pc = ParagraphConstraints(width: 50);
     Paragraph paragraph = pb.build()..layout(pc);
-    canvas.drawParagraph(paragraph, Offset((minRadius + poorRadius * titlesList.length) * (11 + 13 * titlesList.length) / (minRadius + poorRadius * titlesList.length), (minRadius + poorRadius * titlesList.length) * (11 + 13 * titlesList.length) / (minRadius + poorRadius * titlesList.length)));
+    canvas.drawParagraph(
+        paragraph,
+        Offset(
+            (minRadius + poorRadius * titlesList.length) *
+                (11 + 13 * titlesList.length) /
+                (minRadius + poorRadius * titlesList.length),
+            (minRadius + poorRadius * titlesList.length) *
+                (11 + 13 * titlesList.length) /
+                (minRadius + poorRadius * titlesList.length)));
   }
 
-  static Size boundingTextSize(BuildContext context, String text, TextStyle style, {int maxLines = 2 ^ 31, double maxWidth = double.infinity}) {
+  static Size boundingTextSize(
+      BuildContext context, String text, TextStyle style,
+      {int maxLines = 2 ^ 31, double maxWidth = double.infinity}) {
     if (text == null || text.isEmpty) {
       return Size.zero;
     }
-    final TextPainter textPainter = TextPainter(textDirection: TextDirection.ltr, locale: Localizations.maybeLocaleOf(context), text: TextSpan(text: text, style: style), maxLines: maxLines)..layout(maxWidth: maxWidth);
+    final TextPainter textPainter = TextPainter(
+        textDirection: TextDirection.ltr,
+        locale: Localizations.maybeLocaleOf(context),
+        text: TextSpan(text: text, style: style),
+        maxLines: maxLines)
+      ..layout(maxWidth: maxWidth);
     return textPainter.size;
   }
 
@@ -207,7 +256,7 @@ class DashPainter {
     this.step = 2,
     this.span = 2,
     this.pointCount = 0,
-    this.pointWidth,
+    required this.pointWidth,
   });
 
   final double step; //实现的长度
@@ -216,9 +265,11 @@ class DashPainter {
   final double pointWidth; //点划线长
 
   void paint(Canvas canvas, Path path, Paint paint) {
-    final PathMetrics pms = path.computeMetrics(); //为此路径创建一个PathMetrics对象,该对象可以描述有关路径轮廓的各种属性。
+    final PathMetrics pms =
+        path.computeMetrics(); //为此路径创建一个PathMetrics对象,该对象可以描述有关路径轮廓的各种属性。
     final double pointLineLength = pointWidth;
-    final double partLength = step + span * (pointCount + 1) + pointCount * pointLineLength;
+    final double partLength =
+        step + span * (pointCount + 1) + pointCount * pointLineLength;
 
     pms.forEach((PathMetric pm) {
       final int count = pm.length ~/ partLength;
@@ -228,7 +279,8 @@ class DashPainter {
           paint,
         );
         for (int j = 1; j <= pointCount; j++) {
-          final start = partLength * i + step + span * j + pointLineLength * (j - 1);
+          final start =
+              partLength * i + step + span * j + pointLineLength * (j - 1);
           canvas.drawPath(
             pm.extractPath(start, start + pointLineLength),
             paint,

+ 4 - 2
example/lib/three_page.dart

@@ -16,7 +16,7 @@ class ThreePage extends StatefulWidget {
 }
 
 class ThreePageState extends State<ThreePage> {
-  IBulletfRameFactory _iBulletfRameFactory;
+  late IBulletfRameFactory _iBulletfRameFactory;
 
   @override
   void initState() {
@@ -46,7 +46,9 @@ class ThreePageState extends State<ThreePage> {
                   context,
                   ActivateRouter(
                     _iBulletfRameFactory.getBulletfRame().createBulletfRame(),
-                    _iBulletfRameFactory.getBulletfRameColor().getBulletfRameBarrierColor(),
+                    _iBulletfRameFactory
+                        .getBulletfRameColor()
+                        .getBulletfRameBarrierColor(),
                   ));
             },
           ),

+ 5 - 6
example/lib/two_page.dart

@@ -74,11 +74,10 @@ class TwoPageState extends State<TwoPage> {
     }),
   ];
 
+  late ValueNotifier<int> _notifier;
 
-  ValueNotifier<int> _notifier;
-
-  ISideSelectionBarFactory _iSideSelectionBarFactory;
-  ISideSelectionBar _iSideSelectionBar;
+  late ISideSelectionBarFactory _iSideSelectionBarFactory;
+  late ISideSelectionBar _iSideSelectionBar;
 
   @override
   void initState() {
@@ -92,7 +91,8 @@ class TwoPageState extends State<TwoPage> {
 
     _iSideSelectionBarFactory = EvaluationRecordCardSideSelectionBarFactory();
     // _iSideSelectionBarFactory = AbilityAssessmentPhaseSideSelectionBarFactory();
-    _iSideSelectionBar = _iSideSelectionBarFactory.getSideSelectionBar(dataList, (selectIndex) {
+    _iSideSelectionBar =
+        _iSideSelectionBarFactory.getSideSelectionBar(dataList, (selectIndex) {
       print(selectIndex);
     });
   }
@@ -107,4 +107,3 @@ class TwoPageState extends State<TwoPage> {
     );
   }
 }
-