Skip to content

Commit 02145ff

Browse files
committed
[UploadPage] finished glass type chooser
1 parent 21ded1f commit 02145ff

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

lib/routes/upload/upload_cocktail_properties.dart

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:cocktailpedia/util/cocktail.dart';
2+
import 'package:cocktailpedia/util/glass_type.dart';
23
import 'package:cocktailpedia/widgets/custom_theme.dart';
34
import 'package:flutter/material.dart';
45

@@ -15,17 +16,69 @@ class _UploadCocktailPropertiesStates extends State<UploadCocktailProperties> {
1516
final BorderRadius borderRadius = BorderRadius.circular(16);
1617
final Padding divider = const Padding(padding: EdgeInsets.all(16));
1718

19+
GlassType glassType = const AnyGlassType();
20+
1821
bool isShakerNeeded = false;
1922
bool isCocktailSpoonNeeded = false;
2023
bool isCocktailStrainerNeeded = false;
2124

25+
ImageProvider get _imageReference => widget.cocktail.image[0].image;
26+
27+
void _displayGlassChooser() async {
28+
showDialog(
29+
context: context,
30+
builder: (BuildContext context) => CustomTheme(
31+
image: _imageReference,
32+
delay: const Duration(milliseconds: 100),
33+
builder: (ThemeData them) => AlertDialog(
34+
title: const Text("Select a new glass type"),
35+
icon: const Icon(Icons.local_bar),
36+
content: SingleChildScrollView(
37+
child: ListBody(
38+
children: GlassType.glassTypes
39+
.map((e) => InkWell(
40+
onTap: () {
41+
setState(() {
42+
glassType = e;
43+
});
44+
Navigator.of(context).pop();
45+
},
46+
child: Padding(
47+
padding: const EdgeInsets.all(8.0),
48+
child: Row(
49+
children: [
50+
SizedBox(
51+
width: 50,
52+
height: 50,
53+
child: Image(image: e.getImage())),
54+
Text("${e.name} glass")
55+
],
56+
),
57+
),
58+
))
59+
.toList(),
60+
),
61+
),
62+
actions: <Widget>[
63+
TextButton(
64+
child: const Text('Cancel'),
65+
onPressed: () {
66+
Navigator.of(context).pop();
67+
},
68+
),
69+
],
70+
),
71+
),
72+
);
73+
}
74+
2275
@override
2376
Widget build(BuildContext context) {
2477
final double imageWidth = MediaQuery.of(context).size.width - 64;
2578
final double imageHeight = 0.5 * imageWidth;
2679

2780
return CustomTheme(
28-
image: widget.cocktail.image[0].image,
81+
image: _imageReference,
2982
delay: const Duration(milliseconds: 250),
3083
builder: (ThemeData theme) => Scaffold(
3184
appBar: AppBar(
@@ -105,20 +158,22 @@ class _UploadCocktailPropertiesStates extends State<UploadCocktailProperties> {
105158
Material(
106159
color: Colors.transparent,
107160
child: InkWell(
108-
onTap: () {},
161+
onTap: _displayGlassChooser,
109162
child: Padding(
110163
padding: const EdgeInsets.only(
111-
right: 14.0,
164+
right: 24.0,
112165
left: 14.0,
113166
top: 8.0,
114167
bottom: 8.0,
115168
),
116169
child: Row(
170+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
117171
children: [
118172
Text(
119173
"Glass type",
120174
style: Theme.of(context).textTheme.titleMedium,
121175
),
176+
Text(glassType.name)
122177
],
123178
),
124179
),

lib/util/glass_type.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@ class GlassType {
88

99
const GlassType({required this.name, this.description});
1010

11-
ImageProvider getImage() =>
12-
AssetImage("assets/glass-type/${name.toLowerCase()}.png");
11+
ImageProvider getImage() => AssetImage(
12+
"assets/glass-type/${name.toLowerCase()}.png",
13+
);
14+
15+
/// A list of all existing glass types, or at least the ones with an icon associated.
16+
static List<GlassType> get glassTypes => [
17+
const AnyGlassType(),
18+
const GlassType(name: "Cocktail"),
19+
const GlassType(name: "Hurricane"),
20+
const GlassType(name: "Whisky"),
21+
const GlassType(name: "Mug"),
22+
];
1323

1424
@override
1525
String toString() {

0 commit comments

Comments
 (0)