summaryrefslogtreecommitdiffstats
path: root/lib/screen/widgets/guages/guage_widget.dart
blob: fa43958ba2047a7a46322d446bcaaf26d2afaff0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// SPDX-License-Identifier: Apache-2.0

import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_cluster_dashboard/screen/paints/guage_paint.dart';
import 'package:flutter_cluster_dashboard/screen/widgets/guages/guage_props.dart';

class CustomGuage extends StatelessWidget {
  const CustomGuage({
    Key? key,
    required this.mainValue,
    required this.low,
    required this.high,
    required this.label,
    this.zeroTickLabel,
    this.maxTickLabel,
    this.distanceBWTicks,
    this.size,
    this.distLabelTop,
    this.distMainTop,
    this.distTicksBottom,
    this.inPrimaryColor,
    this.outPrimaryColor,
    this.secondaryColor,
  }) : super(key: key);

  final double mainValue;
  final double low;
  final double high;
  final String label;
  final String? zeroTickLabel;
  final String? maxTickLabel;
  final double? distanceBWTicks;
  final double? distTicksBottom;
  final double? distMainTop;
  final double? distLabelTop;
  final double? size;
  final Color? outPrimaryColor;
  final Color? inPrimaryColor;
  final Color? secondaryColor;

  @override
  Widget build(BuildContext context) {
    TextStyle tickStyle = TextStyle(
        color: Colors.white,
        fontSize: ((26 / 400) * (size ?? 400)),
        fontWeight: FontWeight.bold); //20
    TextStyle mainValueTextStyle = TextStyle(
        color: Colors.white,
        fontSize: ((85 / 400) * (size ?? 400)),
        fontWeight: FontWeight.bold); //65
    TextStyle labelTextStyle = TextStyle(
        color: Colors.white,
        fontSize: ((26 / 400) * (size ?? 400)),
        fontWeight: FontWeight.normal); //20
    return SizedBox(
      width: size ?? 400,
      height: size ?? 400,
      child: Stack(
        alignment: Alignment.topCenter,
        children: [
          // Guage painter
          Positioned(
            top: 0,
            child: Transform.rotate(
              angle: (pi / 2) + (GuageProps.minorAngle * (pi / 360.0)),
              child: CustomPaint(
                size: Size(size ?? 400, size ?? 400),
                painter: GuagePainter(
                  low: low,
                  high: high,
                  currentSpeed: mainValue,
                  inPrimaryColor: inPrimaryColor,
                  outPrimaryColor: outPrimaryColor,
                  secondaryColor: secondaryColor,
                ),
              ),
            ),
          ),
          // Guage Label
          Positioned(
            top: distLabelTop ?? ((100 / 400) * (size ?? 400)),
            child: Text(label, style: labelTextStyle),
          ),
          // Guage Main Value
          Positioned(
            top: distMainTop ?? ((150 / 400) * (size ?? 400)),
            child: Text("${mainValue.toInt()}", style: mainValueTextStyle),
          ),
          // Guage Ticks value
          Positioned(
            bottom: distTicksBottom ?? ((80 / 400) * (size ?? 400)),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(zeroTickLabel ?? "", style: tickStyle),
                SizedBox(
                    width: (size != null)
                        ? ((180 * size!) / 400)
                        : (distanceBWTicks ?? 180)),
                Text(maxTickLabel ?? "", style: tickStyle)
              ],
            ),
          ),
        ],
      ),
    );
  }
}