Replace dropdown for impression with icons

This makes it more obvious and is easier and faster to use
This commit is contained in:
Roland Geider
2021-05-18 16:12:20 +02:00
parent 7bd1dcaa26
commit e2ec4669ed
2 changed files with 33 additions and 17 deletions

View File

@@ -560,9 +560,11 @@ class _SessionPageState extends State<SessionPage> {
final timeStartController = TextEditingController();
final timeEndController = TextEditingController();
int impressionValue = 2;
var _session = WorkoutSession();
/// Selected impression: bad, neutral, good
var selectedImpression = [false, true, false];
@override
void initState() {
super.initState();
@@ -593,25 +595,35 @@ class _SessionPageState extends State<SessionPage> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
DropdownButtonFormField(
value: impressionValue,
decoration: InputDecoration(
labelText: AppLocalizations.of(context)!.impression,
),
items: IMPRESSION_MAP.keys.map<DropdownMenuItem<int>>((int key) {
return DropdownMenuItem<int>(
value: key,
child: Text(IMPRESSION_MAP[key]!),
);
}).toList(),
onSaved: (int? newValue) {
_session.impression = newValue!;
},
onChanged: (int? newValue) {
ToggleButtons(
children: <Widget>[
Icon(
Icons.sentiment_very_dissatisfied,
),
Icon(
Icons.sentiment_neutral,
),
Icon(
Icons.sentiment_very_satisfied,
),
],
renderBorder: false,
onPressed: (int index) {
setState(() {
impressionValue = newValue!;
for (int buttonIndex = 0;
buttonIndex < selectedImpression.length;
buttonIndex++) {
_session.impression = index + 1;
if (buttonIndex == index) {
selectedImpression[buttonIndex] = true;
} else {
selectedImpression[buttonIndex] = false;
}
}
});
},
isSelected: selectedImpression,
),
TextFormField(
decoration: InputDecoration(
@@ -650,6 +662,7 @@ class _SessionPageState extends State<SessionPage> {
},
),
),
SizedBox(width: 10),
Flexible(
child: TextFormField(
decoration:

View File

@@ -165,6 +165,9 @@ void main() {
expect(find.text('Workout session'), findsOneWidget);
expect(find.byType(SessionPage), findsOneWidget);
expect(find.byType(Form), findsOneWidget);
expect(find.byIcon(Icons.sentiment_dissatisfied), findsOneWidget);
expect(find.byIcon(Icons.sentiment_neutral), findsOneWidget);
expect(find.byIcon(Icons.sentiment_satisfied), findsOneWidget);
expect(find.byIcon(Icons.chevron_left), findsOneWidget);
expect(find.byIcon(Icons.close), findsOneWidget);
expect(find.byIcon(Icons.chevron_right), findsNothing);