name27 / flutter

0 stars 0 forks source link

키오스크 주문하기 #41

Open name27 opened 1 year ago

name27 commented 1 year ago

image

// ignore_for_file: prefer_const_constructors, avoid_unnecessary_containers
// ignore_for_file: prefer_const_literals_to_create_immutables, non_constant_identifier_names
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<String> orderList = [];

  Widget _buiddList() => Wrap(
        runSpacing: 8.0,
        spacing: 8.0,
        children: [
          MenuTile('assets/option_bokki.png', '떡볶이'),
          MenuTile('assets/option_beer.png', '맥주'),
          MenuTile('assets/option_kimbap.png', '김밥'),
          MenuTile('assets/option_omurice.png', '오므라이스'),
          MenuTile('assets/option_pork_cutlets.png', '돈까스'),
          MenuTile('assets/option_ramen.png', '라면'),
          MenuTile('assets/option_udon.png', '우동'),
        ],
      );
  Container MenuTile(String imgUrl, String name) => Container(
        child: OutlinedButton(
          style: OutlinedButton.styleFrom(
              minimumSize: Size.zero,
              padding: EdgeInsets.all(0),
              fixedSize: Size(125, 110)),
          onPressed: (() {
            orderList.add(name);
            setState(() {});
          }),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Container(
                height: 70,
                decoration: BoxDecoration(
                    image: DecorationImage(
                        image: AssetImage(imgUrl), fit: BoxFit.cover)),
              ),
              Text(
                name,
                style: TextStyle(color: Colors.black),
              ),
              Text(
                '[담기]',
                style: TextStyle(color: Colors.black),
              ),
            ],
          ),
        ),
      );

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text(
              '분식왕 이테디 주문하기',
            ),
            centerTitle: true,
            foregroundColor: Colors.black,
            backgroundColor: Colors.transparent,
            elevation: 0,
            actions: [],
          ),
          body: Padding(
            padding: const EdgeInsets.all(8.0),
            child: SingleChildScrollView(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '주문 리스트',
                    style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                  ),
                  Text('$orderList'),
                  SizedBox(
                    height: 12,
                  ),
                  Text(
                    '음식',
                    style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                  ),
                  _buiddList()
                ],
              ),
            ),
          ),
          floatingActionButton: FloatingActionButton.extended(
            onPressed: () {
              orderList.clear();
              setState(() {});
            },
            label: Text('초기화하기'),
          ),
          floatingActionButtonLocation:
              FloatingActionButtonLocation.centerFloat),
    );
  }
}
name27 commented 1 year ago

image

Main.dart

// ignore_for_file: prefer_const_constructors, avoid_unnecessary_containers
// ignore_for_file: prefer_const_literals_to_create_immutables, non_constant_identifier_names
import 'package:flutter/material.dart';
import 'package:new_project_kiosk_app/OptionCard.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<String> orderList = [];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: Text(
              '분식왕 이테디 주문하기',
            ),
            centerTitle: true,
            foregroundColor: Colors.black,
            backgroundColor: Colors.transparent,
            elevation: 0,
            actions: [],
          ),
          body: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '주문 리스트',
                  style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                ),
                Text('$orderList'),
                SizedBox(
                  height: 12,
                ),
                Text(
                  '음식',
                  style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
                ),
                Expanded(
                  child: GridView(
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: 3),
                    children: [
                      InkWell(
                        onTap: (() {
                          orderList.add('떡볶이');
                          setState(() {});
                        }),
                        child: OptionCard(
                            imgUrl: 'assets/option_bokki.png', foodName:'떡볶이'),
                      ),
                      InkWell(
                        onTap: (() {
                          orderList.add('맥주');
                          setState(() {});
                        }),
                        child: OptionCard(
                            imgUrl: 'assets/option_beer.png', foodName:'맥주'),
                      ),
                      InkWell(
                        onTap: (() {
                          orderList.add('김밥');
                          setState(() {});
                        }),
                        child: OptionCard(
                            imgUrl: 'assets/option_kimbap.png', foodName: '김밥'),
                      ),
                      InkWell(
                        onTap: (() {
                          orderList.add('오므라이스');
                          setState(() {});
                        }),
                        child: OptionCard(
                            imgUrl: 'assets/option_omurice.png', foodName: '오므라이스'),
                      ),
                      InkWell(
                        onTap: (() {
                          orderList.add('돈까스');
                          setState(() {});
                        }),
                        child: OptionCard(
                            imgUrl: 'assets/option_pork_cutlets.png', foodName: '돈까스'),
                      ),
                      InkWell(
                        onTap: (() {
                          orderList.add('라면');
                          setState(() {});
                        }),
                        child: OptionCard(
                            imgUrl: 'assets/option_ramen.png', foodName: '라면'),
                      ),
                      InkWell(
                        onTap: (() {
                          orderList.add('우동');
                          setState(() {});
                        }),
                        child: OptionCard(
                            imgUrl: 'assets/option_udon.png', foodName: '우동'),
                      ),
                    ],
                  ),
                ),
                //_buiddList()
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton.extended(
            onPressed: () {
              orderList.clear();
              setState(() {});
            },
            label: Text('초기화하기'),
          ),
          floatingActionButtonLocation:
          FloatingActionButtonLocation.centerFloat
        ),
    );
  }
}

OptionCard.dart

import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/container.dart';
import 'package:flutter/src/widgets/framework.dart';

class OptionCard extends StatelessWidget {
  const OptionCard({super.key, required this.imgUrl, required this.foodName});
  final String imgUrl;
  final String foodName;
  @override
  Widget build(BuildContext context) {
    return Card(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Expanded(
            child: Image.asset(imgUrl, fit: BoxFit.cover,)
          ),
          Text(foodName),
          Text('[담기]')
        ]
      ),
    );
  }
}