Instantly share code, notes, and snippets.
Last active
October 13, 2021 06:14
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save Eng-MFQ/df0b91adb12f878cbe77b1ea0187736b to your computer and use it in GitHub Desktop.
its example for navigator flutter course
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
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(routes: <String, WidgetBuilder>{ | |
MenuDetails.getPushedName(): (BuildContext context) => new MenuDetails(), | |
}, 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.pushNamed(context, MenuDetails.getPushedName(), | |
arguments: 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: 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 getPushedName(){ | |
return '/MenuDetails'; | |
} | |
const MenuDetails({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
Menu menu = (ModalRoute.of(context)!.settings.arguments) as Menu; | |
return Scaffold( | |
appBar: AppBar(title: Text(menu.title),), | |
body: Column( | |
children: [ | |
AspectRatio( | |
aspectRatio: 16 / 9, | |
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