Skip to content

Commit

Permalink
Merge pull request #122 from kronos-et-al/frontend
Browse files Browse the repository at this point in the history
Improvements to Release version
  • Loading branch information
AlexKutschera authored Nov 6, 2023
2 parents 235ff06 + 6493abb commit 713f371
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 74 deletions.
45 changes: 32 additions & 13 deletions app/lib/view/core/buttons/MensaButton.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class MensaButton extends StatelessWidget {
final void Function()? _onLongPressed;
final String _text;
final String _semanticLabel;
final bool _loading;
final bool _disabled;

/// Creates a new MensaButton.
/// The String [text] is displayed on the button.
Expand All @@ -14,11 +16,15 @@ class MensaButton extends StatelessWidget {
required onPressed,
onLongPressed,
required text,
required String semanticLabel})
required String semanticLabel,
bool loading = false,
bool disabled = false})
: _onPressed = onPressed,
_onLongPressed = onLongPressed,
_text = text,
_semanticLabel = semanticLabel;
_semanticLabel = semanticLabel,
_loading = loading,
_disabled = disabled;

/// Builds the widget.
@override
Expand All @@ -27,16 +33,29 @@ class MensaButton extends StatelessWidget {
button: true,
label: _semanticLabel,
child: MaterialButton(
textColor: Theme.of(context).colorScheme.onSurface,
color: Theme.of(context).colorScheme.surface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4.0),
),
elevation: 0,
highlightElevation: 0,
onPressed: _onPressed,
onLongPress: _onLongPressed,
child: Text(_text),
));
textColor: Theme.of(context).colorScheme.onSurface,
color: Theme.of(context).colorScheme.surface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4.0),
),
elevation: 0,
highlightElevation: 0,
onPressed: _disabled ? null : _onPressed,
onLongPress: _onLongPressed,
child: Stack(
alignment: Alignment.center,
children: [
Text(
_text,
style: TextStyle(
color: _loading
? Colors.transparent
: Theme.of(context).colorScheme.onSurface),
),
if (_loading)
SizedBox(
width: 16, height: 16, child: CircularProgressIndicator(color: Theme.of(context).colorScheme.onSurface))
],
)));
}
}
85 changes: 64 additions & 21 deletions app/lib/view/detail_view/DetailsPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ class DetailsPageState extends State<DetailsPage> {

final DateFormat _dateFormat = DateFormat.yMd("de_DE");

int? _changedRating;

@override
void initState() {
_changedRating = widget._meal.individualRating;
super.initState();
}

@override
void didChangeDependencies() {
_changedRating = widget._meal.individualRating;
super.didChangeDependencies();
}

@override
Widget build(BuildContext context) {
// These provider are necessary for the synchronization of each other. They need to be initialized even if they are unused.
Expand Down Expand Up @@ -320,15 +334,23 @@ class DetailsPageState extends State<DetailsPage> {
)),
Row(children: [
MensaRatingInput(
value: meal.individualRating
.toDouble(),
disabled: true,
value:
_changedRating?.toDouble() ??
meal.individualRating
.toDouble(),
color: Theme.of(context)
.colorScheme
.onSurface,
size: 20,
max: 5,
onChanged: (_) {},
onChanged: (value) async {
setState(() {
_changedRating = value;
});
await mealAccess
.updateMealRating(
value.toInt(), meal);
},
),
const Spacer(),
MensaButton(
Expand Down Expand Up @@ -367,25 +389,46 @@ class DetailsPageState extends State<DetailsPage> {
fontSize: 20,
fontWeight: FontWeight.bold,
)),
(meal.lastServed != null || meal.nextServed != null || meal.numberOfOccurance != null)
(meal.lastServed != null ||
meal.nextServed != null ||
meal.numberOfOccurance !=
null)
? const SizedBox(
height: 8,
)
height: 8,
)
: const SizedBox(
height: 0,
),
meal.lastServed != null ? Text(FlutterI18n.translate(
context, "mealDetails.lastServed", translationParams: {
"lastServed": _dateFormat.format(meal.lastServed!)
})) : const SizedBox(height: 0),
meal.nextServed != null ? Text(FlutterI18n.translate(
context, "mealDetails.nextServed", translationParams: {
"nextServed": _dateFormat.format(meal.nextServed!)
})) : const SizedBox(height: 0),
meal.numberOfOccurance != null ? Text(FlutterI18n.translate(
context, "mealDetails.frequency", translationParams: {
"frequency": meal.numberOfOccurance.toString()
})) : const SizedBox(height: 0),
height: 0,
),
meal.lastServed != null
? Text(FlutterI18n.translate(
context,
"mealDetails.lastServed",
translationParams: {
"lastServed":
_dateFormat.format(
meal.lastServed!)
}))
: const SizedBox(height: 0),
meal.nextServed != null
? Text(FlutterI18n.translate(
context,
"mealDetails.nextServed",
translationParams: {
"nextServed":
_dateFormat.format(
meal.nextServed!)
}))
: const SizedBox(height: 0),
meal.numberOfOccurance != null
? Text(FlutterI18n.translate(
context,
"mealDetails.frequency",
translationParams: {
"frequency": meal
.numberOfOccurance
.toString()
}))
: const SizedBox(height: 0),
],
),
),
Expand Down
11 changes: 10 additions & 1 deletion app/lib/view/detail_view/MealRatingDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class MealRatingDialog extends StatefulWidget {
class _MealRatingDialogState extends State<MealRatingDialog> {
int? rating;

bool _loading = false;

@override
Widget build(BuildContext context) {
Meal meal = widget._meal;
Expand Down Expand Up @@ -50,16 +52,23 @@ class _MealRatingDialogState extends State<MealRatingDialog> {
children: [
const Spacer(),
MensaButton(
disabled: _loading,
loading: _loading,
semanticLabel: FlutterI18n.translate(
context, "semantics.mealRatingSubmit"),
onPressed: () async {
setState(() {
_loading = true;
});
final result =
await context.read<IMealAccess>().updateMealRating(
rating!,
meal,
);
if (!context.mounted) return;

setState(() {
_loading = false;
});
if (result) {
final snackBar = SnackBar(
content: Text(
Expand Down
72 changes: 43 additions & 29 deletions app/lib/view/detail_view/UploadImageDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class _UploadImageDialogState extends State<UploadImageDialog> {
XFile? _image;
Uint8List? _imageBytes;

bool _loading = false;

@override
Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
Expand All @@ -80,33 +82,39 @@ class _UploadImageDialogState extends State<UploadImageDialog> {
onPressed: () async {
final ImagePicker picker = ImagePicker();
final XFile? image = await picker.pickImage(
source: ImageSource.gallery);
source: ImageSource.gallery, imageQuality: 90);
Uint8List bytes = await image!.readAsBytes();
setState(() {
_image = image;
_imageBytes = bytes;
});
},
text: FlutterI18n.translate(
context, "image.labelSelectImage"),
semanticLabel: FlutterI18n.translate(
context, "image.labelSelectImage"))),
(Platform.isAndroid || Platform.isIOS)
? const SizedBox(
width: 8,
)
: Container(),
(Platform.isAndroid || Platform.isIOS)
? MensaTapable(
onTap: () async {
final ImagePicker picker = ImagePicker();
final XFile? image = await picker.pickImage(
source: ImageSource.camera, imageQuality: 90);
Uint8List bytes = await image!.readAsBytes();
setState(() {
_image = image;
_imageBytes = bytes;
});
},
text: FlutterI18n.translate(context, "image.labelSelectImage"),
semanticLabel: FlutterI18n.translate(context, "image.labelSelectImage"))),
(Platform.isAndroid || Platform.isIOS) ? const SizedBox(
width: 8,
) : Container(),
(Platform.isAndroid || Platform.isIOS) ? MensaTapable(
onTap: () async {
final ImagePicker picker = ImagePicker();
final XFile? image =
await picker.pickImage(source: ImageSource.camera);
Uint8List bytes = await image!.readAsBytes();
setState(() {
_image = image;
_imageBytes = bytes;
});
},
semanticLabel: FlutterI18n.translate(context, "image.labelTakeImage"),
child: const Padding(
padding: EdgeInsets.all(2),
child: CameraIcon())) : Container(),
semanticLabel: FlutterI18n.translate(
context, "image.labelTakeImage"),
child: const Padding(
padding: EdgeInsets.all(2), child: CameraIcon()))
: Container(),
],
),
const SizedBox(height: 16),
Expand All @@ -130,8 +138,8 @@ class _UploadImageDialogState extends State<UploadImageDialog> {
},
),
TextSpan(
text: FlutterI18n.translate(context,
"image.linkFirstPointSecondText"))
text: FlutterI18n.translate(
context, "image.linkFirstPointSecondText"))
]),
),
],
Expand All @@ -142,20 +150,26 @@ class _UploadImageDialogState extends State<UploadImageDialog> {
children: [
const Spacer(),
MensaButton(
disabled: _loading || _image == null,
loading: _loading,
semanticLabel: FlutterI18n.translate(
context, "semantics.imageSubmitUpload"),
onPressed: () async {

if (_image != null && _imageBytes != null) {
print(_image!.mimeType);
MediaType _mediaType = MediaType.parse(parseMimeType(_image!));
print(_mediaType);
setState(() {
_loading = true;
});
final result = await context
.read<IImageAccess>()
.linkImage(_imageBytes!,
MediaType.parse(parseMimeType(_image!)), widget._meal);
.linkImage(
_imageBytes!,
MediaType.parse(parseMimeType(_image!)),
widget._meal);
if (!context.mounted) return;

setState(() {
_loading = false;
});
Navigator.pop(context);

switch (result) {
Expand Down
Loading

0 comments on commit 713f371

Please sign in to comment.