-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restaurant_card #1311
Closed
Closed
Restaurant_card #1311
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:uni_ui/generic_card.dart'; | ||
import 'package:phosphor_flutter/phosphor_flutter.dart'; | ||
|
||
class MenuItem { | ||
final String name; | ||
final String type; | ||
|
||
MenuItem({required this.name, required this.type}); | ||
} | ||
|
||
class RestaurantCard extends StatefulWidget { | ||
final String title; | ||
final String establishmentType; | ||
final List<MenuItem> menuItems; | ||
|
||
const RestaurantCard({ | ||
super.key, | ||
required this.title, | ||
required this.establishmentType, | ||
required this.menuItems, | ||
}); | ||
|
||
@override | ||
_RestaurantCardState createState() => _RestaurantCardState(); | ||
} | ||
|
||
class _RestaurantCardState extends State<RestaurantCard> { | ||
bool isFavorite = false; | ||
|
||
void _toggleFavorite() { | ||
setState(() { | ||
isFavorite = !isFavorite; | ||
}); | ||
} | ||
|
||
IconData? _getIconForMenuItemType(String type) { | ||
switch (type.toLowerCase()) { | ||
case 'meat': | ||
return PhosphorIconsBold.cow; | ||
case 'fish': | ||
return PhosphorIconsBold.fish; | ||
default: | ||
return PhosphorIconsBold.leaf; | ||
} | ||
} | ||
|
||
Color _getIconColorForMenuItemType(String type) { | ||
return Theme.of(context).colorScheme.primary; | ||
} | ||
Comment on lines
+48
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks a little redundant. I would remove that and put the theme property directly on line 116. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense !! |
||
|
||
@override | ||
Widget build(BuildContext context) { | ||
Widget establishmentIcon; | ||
switch (widget.establishmentType.toLowerCase()) { | ||
case 'cafeteria': | ||
case 'snack-bar': | ||
establishmentIcon = Icon(PhosphorIconsBold.hamburger, color: Theme.of(context).colorScheme.primary, size: 32.0); | ||
break; | ||
case 'cantina': | ||
case 'grill': | ||
establishmentIcon = Icon(PhosphorIconsBold.cookingPot, color: Theme.of(context).colorScheme.primary, size: 32.0); | ||
break; | ||
case 'restaurant': | ||
default: | ||
establishmentIcon = Icon(PhosphorIconsBold.chefHat, color: Theme.of(context).colorScheme.primary, size: 32.0); | ||
break; | ||
} | ||
|
||
return GenericCard( | ||
color: Theme.of(context).colorScheme.surface, | ||
borderRadius: 16.0, | ||
padding: const EdgeInsets.all(16.0), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Row( | ||
children: [ | ||
establishmentIcon, | ||
const SizedBox(width: 8), | ||
Text( | ||
widget.title, | ||
style: TextStyle( | ||
fontSize: 20, | ||
fontWeight: FontWeight.bold, | ||
color: Theme.of(context).colorScheme.primary, | ||
), | ||
), | ||
const Spacer(), | ||
GestureDetector( | ||
onTap: _toggleFavorite, | ||
child: Icon( | ||
isFavorite | ||
? PhosphorIconsFill.heartStraight | ||
: PhosphorIconsRegular.heartStraight, | ||
color: Theme.of(context).colorScheme.primary, | ||
), | ||
), | ||
], | ||
), | ||
const SizedBox(height: 8), | ||
Divider( | ||
color: Theme.of(context).dividerColor, | ||
thickness: 1.0, | ||
), | ||
const SizedBox(height: 8), | ||
Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: widget.menuItems.map((item) { | ||
return Padding( | ||
padding: const EdgeInsets.symmetric(vertical: 8.0), | ||
child: Row( | ||
children: [ | ||
Icon( | ||
_getIconForMenuItemType(item.type), | ||
color: _getIconColorForMenuItemType(item.type), | ||
size: 24.0, | ||
), | ||
const SizedBox(width: 8), | ||
Text( | ||
item.name, | ||
style: TextStyle( | ||
fontSize: 16, | ||
color: Theme.of(context).colorScheme.primary, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
}).toList(), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extend a
StatelessWidget
instead.The
isFavorite
state should be outside this widget and passed as a simple boolean argument. Also add the possibility to pass void function to run on favorite icon click.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okok! I'll fix that 😊