This repository has been archived by the owner on May 10, 2022. It is now read-only.
/
main.dart
143 lines (130 loc) · 4.12 KB
/
main.dart
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/// Copyright (c) 2020 arconsis IT-Solutions GmbH
/// Licensed under MIT (https://github.com/arconsis/measurements/blob/master/LICENSE)
import 'package:document_measure/document_measure.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'colors.dart';
class MetadataRepository {}
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
static String originalTitle = 'Measurement app';
String title = originalTitle;
bool measure = true;
bool showDistanceOnLine = true;
bool showTolerance = false;
bool zoomed = false;
List<LengthUnit> unitsOfMeasurement = [
Meter.asUnit(),
Millimeter.asUnit(),
Inch.asUnit(),
Foot.asUnit()
];
int unitIndex = 0;
MeasurementController controller;
@override
void initState() {
super.initState();
controller = MeasurementController();
}
Color getButtonColor(bool selected) {
if (selected) {
return selectedColor;
} else {
return unselectedColor;
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Color(0xff1280b3),
title: Row(
children: <Widget>[
IconButton(
onPressed: () => setState(() {
measure = !measure;
title = originalTitle;
}),
icon: Icon(
Icons.straighten,
color: getButtonColor(
measure,
),
),
),
IconButton(
onPressed: () =>
setState(() => showDistanceOnLine = !showDistanceOnLine),
icon: Icon(
Icons.vertical_align_bottom,
color: getButtonColor(showDistanceOnLine),
),
),
SizedBox.fromSize(
child: MaterialButton(
shape: CircleBorder(),
onPressed: () =>
setState(() => showTolerance = !showTolerance),
child: Text('±'),
textColor: getButtonColor(showTolerance),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
size: Size(52, 52),
),
SizedBox.fromSize(
child: MaterialButton(
shape: CircleBorder(),
onPressed: () => setState(() =>
unitIndex = (unitIndex + 1) % unitsOfMeasurement.length),
child: Text(unitsOfMeasurement[unitIndex].getAbbreviation()),
textColor: unselectedColor,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
size: Size(64, 64),
),
IconButton(
onPressed: () {
if (zoomed) {
controller.resetZoom();
} else {
controller.zoomToLifeSize();
}
setState(() {
zoomed = !zoomed;
});
},
icon:
Icon(Icons.zoom_out_map, color: getButtonColor(zoomed))),
],
),
),
body: Center(
child: Measurements(
child: Image.asset(
'assets/images/floorplan448x449mm.png',
),
measurementInformation: MeasurementInformation(
scale: 1 / 50.0,
documentWidthInLengthUnits: Millimeter(448),
documentHeightInLengthUnits: Millimeter(449),
targetLengthUnit: unitsOfMeasurement[unitIndex],
),
controller: controller,
showDistanceOnLine: showDistanceOnLine,
distanceStyle: DistanceStyle(
showTolerance: showTolerance,
),
measure: measure,
),
),
),
);
}
}