본문 바로가기

study/flutter

플러터(flutter) showCupertinoModalPopup 사용

import 'dart:core';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

// void main(){
//   runApp(MyAPP());
// }
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Dice game',
      home: LogIn(),
    );
  }
}

class LogIn extends StatefulWidget {
  @override
  _LogInState createState() => _LogInState();
}

class _LogInState extends State<LogIn> {
  TextEditingController _ProcessingValueEditingController =
      TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Log ins'),
        backgroundColor: Colors.redAccent,
        centerTitle: true,
        leading: IconButton(
          icon: Icon(Icons.menu),
          onPressed: () {},
        ),
        actions: [
          IconButton(
            onPressed: () {},
            icon: Icon(Icons.search_outlined),
          ),
        ],
      ),
      body: GestureDetector(
        onTap: () {
          HapticFeedback.mediumImpact();
          _CupertinoMapQuestion(context);
        },
        child: Container(
          width: MediaQuery.of(context).size.width,
          padding: const EdgeInsets.only(right: 10, left: 10, top: 10),
          child: TextFormField(
            style: TextStyle(fontSize: 16),
            decoration: InputDecoration(
              enabled: false,
              contentPadding:
                  new EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0),
              isDense: true,
              hintText: "선택하고 싶은 항목 선택",
              enabledBorder: UnderlineInputBorder(
                borderSide: BorderSide(color: Colors.grey),
              ),
            ),
            controller: _ProcessingValueEditingController,
          ),
        ),
      ),
    );
  }

  _CupertinoMapQuestion(BuildContext context) {
    // showCupertinoModalPopup 사용
    return showCupertinoModalPopup(
        context: context,
        builder: (BuildContext context) => Theme(
              data: ThemeData.light(),
              child: CupertinoActionSheet(
                actions: [
                  CupertinoActionSheetAction(
                    child: Text('1111111'),
                    onPressed: () {
                      HapticFeedback.mediumImpact();
                      _ProcessingValueEditingController.text = '1111111';
                      Navigator.of(context).pop();
                    },
                  ),
                  CupertinoActionSheetAction(
                    child: Text('2222222'),
                    onPressed: () {
                      HapticFeedback.mediumImpact();
                      _ProcessingValueEditingController.text = '2222222';
                      Navigator.of(context).pop();
                    },
                  ),
                  CupertinoActionSheetAction(
                    child: Text('3333333'),
                    onPressed: () {
                      HapticFeedback.mediumImpact();
                      _ProcessingValueEditingController.text = '3333333';
                      Navigator.of(context).pop();
                    },
                  ),
                ],
                cancelButton: CupertinoActionSheetAction(
                    child: Text('취소'),
                    onPressed: () {
                      HapticFeedback.mediumImpact();
                      Navigator.of(context).pop();
                    }),
              ),
            ));
  }
}