name27 / flutter

0 stars 0 forks source link

키오스크 주문하기 .map(), Chip, Navigator, if문 #59

Open name27 opened 1 year ago

name27 commented 1 year ago

image image image

수정사항 orderList.isEmpty == true -> orderList.isEmpty orderList.isEmpty 자체가 bool값이기 때문에 true 필요 없음

// 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 StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: KioskPage(),
    );
  }
}

class KioskPage extends StatefulWidget {
  const KioskPage({super.key});
  @override
  State<KioskPage> createState() => _KioskPageState();
}

class _KioskPageState extends State<KioskPage> {
  List<String> orderList = [];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: InkWell(
            onDoubleTap: (() {
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => AdminPage()));
            }),
            child: 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),
              ),
              orderList.isEmpty
                  ? Center(child: Text('주문할 메뉴가 없습니다'))
                  : Wrap(
                      children: orderList
                          .map((e) => Chip(
                                label: Text(e),
                                onDeleted: () {
                                  orderList.remove(e);
                                  setState(() {});
                                },
                              ))
                          .toList(),
                    ),
              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: Visibility(
          visible: !orderList.isEmpty,
          child: FloatingActionButton.extended(
            onPressed: () {},
            label: Text('결제하기'),
          ),
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat);
  }
}

class AdminPage extends StatelessWidget {
  const AdminPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('관리자 페이지'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(12.0),
        child: Column(
          children: [
            Text('메뉴 추가'),
            SizedBox(
              height: 12,
            ),
            Text('메뉴 수정'),
            SizedBox(
              height: 12,
            ),
            Text('메뉴 삭제')
          ],
        ),
      ),
    );
  }
}
name27 commented 1 year ago

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';
import 'package:new_project_kiosk_app/main_page.dart';

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

class KioskApp extends StatelessWidget {
  const KioskApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: KioskPage(),
    );
  }
}

main_page.dart

import 'package:flutter/material.dart';
import 'package:new_project_kiosk_app/OptionCard.dart';
import 'package:new_project_kiosk_app/admin_page.dart';

class KioskPage extends StatefulWidget {
  const KioskPage({super.key});
  @override
  State<KioskPage> createState() => _KioskPageState();
}

class _KioskPageState extends State<KioskPage> {
  List<String> orderList = [];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: GestureDetector(
            onDoubleTap: (() {
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => AdminPage()));
            }),
            child: 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),
              ),
              Container(
                alignment: Alignment.center,
                height: 50,
                child: orderList.isNotEmpty
                    ? ListView.builder(
                        scrollDirection: Axis.horizontal,
                        itemCount: orderList.length,
                        itemBuilder: (context, index) {
                          return Chip(
                            label: Text(orderList[index]),
                            onDeleted: () {
                              orderList.removeAt(index);
                              setState(() {});
                            },
                          );
                        }
                      )
                    : Text('주문할 메뉴가 없습니다'),
              ),

              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: orderList.isNotEmpty ?
        FloatingActionButton.extended(
            onPressed: () {},
            label: Text('결제하기'),
        ): null,
        floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat);
  }
}

admin_page.dart

import 'package:flutter/material.dart';

class AdminPage extends StatelessWidget {
  const AdminPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('관리자 페이지'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(12.0),
        child: ListView(
          children: [
            ListTile(
              title: Text('메뉴 추가하기'),
            ),
            ListTile(
              title: Text('키오스크 화면 잠그기'),
            ),
            ListTile(
              title: Text('매장 등록 정보'),
            ),
          ],
        ),
      ),
    );
  }
}

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('[담기]')
        ]
      ),
    );
  }
}