Skip to content
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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/uni_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.0.2"
phosphor_flutter:
dependency: transitive
description:
name: phosphor_flutter
sha256: "8a14f238f28a0b54842c5a4dc20676598dd4811fcba284ed828bd5a262c11fde"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
platform:
dependency: transitive
description:
Expand Down
136 changes: 136 additions & 0 deletions packages/uni_ui/lib/restaurant_card.dart
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) {
Comment on lines +28 to +37
Copy link
Member

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.

Copy link
Contributor Author

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 😊

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
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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(),
),
],
),
);
}
}