인프런 - 강의/플루터로 앱 만들기 고고(입문)

21 - Todo App - 4

----___<<<<< 2020. 5. 7. 19:12

import 'package:flutter/material.dart';

import 'Second.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Alert(),
    );
  }
}

class Alert extends StatefulWidget {
  @override
  _AlertState createState() => _AlertState();
}

class _AlertState extends State<Alert> {

  final myController = TextEditingController();

  List<String> listViewdata = [
    "a",
    "b",
    "c",
    "d",
    "e",
    "f",
  ];

  void plus(){
    setState(() {
      listViewdata.add(myController.text);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: <Widget>[
          Expanded(
            child: ListView(
              children : listViewdata.map((data){
                return ListTile(
                  title : Text(data),
                  onTap: (){
                    print(data);
                    Navigator.push(
                        context,
                        MaterialPageRoute(builder: (context) => Second(str : data))
                    );
                  },
                );
              }).toList()
            ),
          ),
          Center(
            child: RaisedButton(
              child: Text("AlertButton"),
              onPressed: (){
                showAlertDialog(context);
              },
            ),
          ),
        ],
      ),
    );
  }

  showAlertDialog(BuildContext context) {

    Widget okButton = FlatButton(
      child: Text("OK"),
      onPressed: (){
        plus();
        Navigator.of(context).pop();
      },
    );

    AlertDialog alert = AlertDialog(
      title: Text("title"),
      content: TextField(
        controller: myController,
        decoration: InputDecoration(hintText: "Input 입력하세요"),
      ),
      actions: [
        okButton,
      ],
    );

    showDialog(
      context: context,
      builder: (BuildContext context) {
        return alert;
      }
    );

  }

}

 

import 'package:flutter/material.dart';

class Second extends StatelessWidget {

  final String str;

  Second({Key key, @required this.str}) : super(key : key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text(str),
    );
  }
}

 

 

 

 

 

'인프런 - 강의 > 플루터로 앱 만들기 고고(입문)' 카테고리의 다른 글

23 - API - 2  (0) 2020.05.21
22 - API - 1  (0) 2020.05.21
20 - Todo App - 3  (0) 2020.05.07
19 - Todo App - 2  (0) 2020.05.07
18 - Todo App - 1  (0) 2020.05.07