Skip to content

Instantly share code, notes, and snippets.

@Eng-MFQ
Last active October 13, 2021 06:14
Show Gist options
  • Save Eng-MFQ/4ea4c309281ec3e16c94e0aff14044f6 to your computer and use it in GitHub Desktop.
Save Eng-MFQ/4ea4c309281ec3e16c94e0aff14044f6 to your computer and use it in GitHub Desktop.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'Menu.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(home: MenuScreen());
}
}
class MenuScreen extends StatefulWidget {
const MenuScreen({Key? key}) : super(key: key);
@override
_MenuScreenState createState() => _MenuScreenState();
}
class _MenuScreenState extends State<MenuScreen> {
late List<Menu> menu;
@override
void initState() {
menu = Menu.createMenu();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(appBar: AppBar(), body: myWidget());
}
Widget myWidget() {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
color: Colors.greenAccent,
child: GridView.count(
crossAxisCount: 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
children: [
for (int i = 0; i < menu.length; i++)
InkWell(
onTap: () {
Navigator.push(
context, MenuDetails.getRoute(menu[i])
);
},
child: Card(
color: menu[i].isClicked ? Colors.blue : Colors.white,
elevation: 4,
child: Column(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Hero(
tag: 'heroTag_img',
child: Image.asset(
'${menu[i].imagePath}',
color:
menu[i].isClicked ? Colors.amber : Colors.black54,
),
),
)),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text(
'${menu[i].title}',
style: TextStyle(fontSize: 21),
),
IconButton(
onPressed: () {
setState(() {
menu[i].isFav = !menu[i].isFav;
});
},
icon: Icon(menu[i].isFav
? Icons.favorite
: Icons.favorite_border_rounded)),
],
)
],
),
),
),
],
),
);
}
}
class MenuDetails extends StatelessWidget {
static PageRouteBuilder getRoute(Menu menu) {
return PageRouteBuilder(
opaque: false,
pageBuilder: (BuildContext context, _, __) {
return MenuDetails(menu);
},
transitionsBuilder: (___, Animation<double> animation, ____, Widget child) {
return FadeTransition(
opacity: animation,
child: RotationTransition(
turns: Tween<double>(begin: 0.5, end: 1.0).animate(animation),
child: child,
),
);
}
);
}
Menu menu;
MenuDetails(this.menu, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(menu.title),
),
body: Column(
children: [
Container(
color: Colors.amber,
child: AspectRatio(
aspectRatio: 4,
child: Hero(
tag: 'heroTag_img',
child: Image.asset(
menu.imagePath,
color: Colors.blue,
),
)),
),
Text(
menu.title,
style: TextStyle(fontSize: 50),
)
],
),
);
}
}
import 'package:syhaib_flutter/res/Images.dart';
class Menu {
String title;
String imagePath;
bool isFav;
bool isClicked;
Menu(this.title, this.imagePath,
{this.isFav = false, this.isClicked = false});
static List<Menu> createMenu() {
List<Menu> menu = [];
Menu breakfast = new Menu('Breakfast', 'images/breakfast.png');
Menu dinner = Menu('Dinner', 'images/dinner.png');
Menu fast = Menu('Fast Food', 'images/fashfood.png');
Menu lunch = Menu('Lunch', 'images/Lunch.png');
menu.add(breakfast);
menu.add(dinner);
menu.add(fast);
menu.add(lunch);
return menu;
}
@override
String toString() {
return 'Menu{title: $title, imagePath: $imagePath}';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment