Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Projet mobile image
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Quentin DU BOIS
Projet mobile image
Commits
8ba0f2df
Commit
8ba0f2df
authored
Sep 19, 2021
by
Quentin DU BOIS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
158d47da
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
178 additions
and
0 deletions
+178
-0
TP1.dart
Mobile/TP1.dart
+178
-0
No files found.
Mobile/TP1.dart
0 → 100644
View file @
8ba0f2df
import
'package:flutter/material.dart'
;
void
main
(
)
{
runApp
(
const
MyApp
());
}
const
entryStyle
=
TextStyle
(
fontSize:
25
,
color:
Colors
.
indigo
,
);
const
labelStyle
=
TextStyle
(
fontSize:
20
,
color:
Colors
.
black54
,
);
class
MyApp
extends
StatefulWidget
{
const
MyApp
({
Key
?
key
})
:
super
(
key:
key
);
@override
_MyAppState
createState
()
=>
_MyAppState
();
}
class
_MyAppState
extends
State
<
MyApp
>
{
double
_enteredNumber
=
0.0
;
String
_startingUnit
=
''
;
String
_arrivalUnit
=
''
;
String
?
_message
=
''
;
final
Map
<
String
,
int
>
_measureMap
=
{
'meters'
:
0
,
'kilometers'
:
1
,
'grams'
:
2
,
'kilograms'
:
3
,
'feet'
:
4
,
'miles'
:
5
,
'pounds'
:
6
,
'ounces'
:
7
};
final
dynamic
_formulas
=
{
'0'
:
[
1
,
0.001
,
0
,
0
,
3.28084
,
0.000621371
,
0
,
0
],
'1'
:
[
1000
,
1
,
0
,
0
,
3280.84
,
0.621371
,
0
,
0
],
'2'
:
[
0
,
0
,
1
,
0.0001
,
0
,
0
,
0.00220462
,
0.035274
],
'3'
:
[
0
,
0
,
1000
,
1
,
0
,
0
,
2.20462
,
35.274
],
'4'
:
[
0.3048
,
0.0003048
,
0
,
0
,
1
,
0.000189394
,
0
,
0
],
'5'
:
[
1609.34
,
1.60934
,
0
,
0
,
5280
,
1
,
0
,
0
],
'6'
:
[
0
,
0
,
453.592
,
0.453592
,
0
,
0
,
1
,
16
],
'7'
:
[
0
,
0
,
28.3495
,
0.0283495
,
0
,
0
,
0.0625
,
1
],
};
@override
void
initState
()
{
_enteredNumber
=
0.0
;
_startingUnit
=
_measureMap
.
keys
.
first
;
_arrivalUnit
=
_measureMap
.
keys
.
first
;
super
.
initState
();
}
void
convert
(
double
value
,
String
from
,
String
to
)
{
int
numFrom
=
_measureMap
[
from
]
??
0
;
int
numTo
=
_measureMap
[
to
]
??
0
;
var
multiplier
=
_formulas
[
numFrom
.
toString
()][
numTo
];
var
result
=
value
*
multiplier
;
String
message
;
if
(
result
==
0
)
{
message
=
'This conversion cannot be released, please try an other value'
;
}
else
{
message
=
'
${value.toString()}
$to
\n
is equal to
\n
${result.toString()}
$to
'
;
setState
(()
{
_message
=
message
;
});
}
}
// Widgets
//============================================================================
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
title:
'Measures convertor'
,
home:
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'Measures convertor'
),
backgroundColor:
Colors
.
indigo
,
),
body:
Container
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
20
),
child:
Column
(
children:
[
const
Spacer
(),
const
Text
(
'Enter a measure to convert :'
,
style:
entryStyle
,
),
TextField
(
onChanged:
(
text
)
{
var
vr
=
double
.
tryParse
(
text
);
if
(
vr
!=
null
)
{
setState
(()
{
_enteredNumber
=
vr
;
});
}
},
),
const
Spacer
(),
const
Text
(
'From'
,
style:
labelStyle
,
),
DropdownButton
(
value:
_startingUnit
,
items:
_measureMap
.
keys
.
map
((
String
unit
)
{
return
DropdownMenuItem
<
String
>(
value:
unit
,
child:
Text
(
unit
),
);
}).
toList
(),
onChanged:
(
String
?
unit
)
{
setState
(()
{
_startingUnit
=
unit
??
_measureMap
.
keys
.
first
;
});
},
),
const
Spacer
(),
const
Text
(
'to'
,
style:
labelStyle
,
),
DropdownButton
(
value:
_arrivalUnit
,
items:
_measureMap
.
keys
.
map
((
String
unit
)
{
return
DropdownMenuItem
<
String
>(
value:
unit
,
child:
Text
(
unit
),
);
}).
toList
(),
onChanged:
(
String
?
unit
)
{
setState
(()
{
_arrivalUnit
=
unit
??
_measureMap
.
keys
.
first
;
});
},
),
const
Spacer
(
flex:
2
,
),
ElevatedButton
(
onPressed:
()
{
if
(
_enteredNumber
==
0
)
{
return
;
}
else
{
convert
(
_enteredNumber
,
_startingUnit
,
_arrivalUnit
);
}
},
child:
const
Text
(
'Convert'
,
style:
entryStyle
,
),
),
const
Spacer
(),
Text
(
_message
??
''
,
textAlign:
TextAlign
.
center
,
style:
labelStyle
,
),
const
Spacer
(
flex:
8
,
),
],
),
),
),
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment