Skip to content

Instantly share code, notes, and snippets.

@Eng-MFQ
Created October 2, 2021 08:29
Show Gist options
  • Save Eng-MFQ/af6fda1f70e4afc9cef44c94fb6dba6c to your computer and use it in GitHub Desktop.
Save Eng-MFQ/af6fda1f70e4afc9cef44c94fb6dba6c to your computer and use it in GitHub Desktop.
Good description
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(home: MenuScreen());
}
}
class MenuScreen extends StatelessWidget {
const MenuScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(appBar: AppBar(),body: myWidget());
}
Widget myWidget() {
List<Menu> menu = Menu.createMenu();
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++)
Card(
elevation: 4,
child: Column(
children: [
Expanded(child: Image.asset('${menu[i].imagePath}')),
Text(
'${menu[i].title}',
style: TextStyle(fontSize: 16),
)
],
),
),
],
),
);
}
}
class Menu {
String title;
String imagePath;
Menu(this.title, this.imagePath);
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