2 글 보임 - 1 에서 2 까지 (총 2 중에서)
-
글쓴이글
-
2025년 1월 10일 17:39 #135079

강현우참가자inputData에 text 정보를 저장하고,
if (inputData != ' '){ 내가만든함수};이런식의 이프문을 만들었는데, 왜 inputData가 빈 텍스트일때도 함수가 실행될까요??
import 'package:flutter/material.dart';
void main(){ runApp( MaterialApp( home: MyApp() ) ); }class MyApp extends StatefulWidget { MyApp({Key? key}) : super(key: key); @override State<MyApp> createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { var total = 3; var name = ['김영숙', '호날두', '피자집']; addOne(){ setState(() { total++; }); } addname(a){ setState(() { name.add(a); }); }@override Widget build(BuildContext context) { return Scaffold( floatingActionButton: FloatingActionButton( onPressed: () { showDialog( context: context, builder: (context) { return DialogUI(addone: addOne, addname: addname, ); } ); } ), appBar: AppBar(title: Text(total.toString())), body: ListView.builder( itemCount: name.length, itemBuilder: (c,i){ return ListTile( leading: Icon(Icons.account_box), title: Text(name[i]) ); } ), ); } }class DialogUI extends StatelessWidget { DialogUI({Key?key, this.addone, this.addname}): super(key:key); final addone; final addname; var inputData=TextEditingController();@override Widget build(BuildContext context) { return Dialog( child: Column( children: [ TextField(controller: inputData), TextButton(child: Text('완료'), onPressed:(){ if (inputData!=''){ addone(); addname(inputData.text); }; }), TextButton( child: Text('취소'), onPressed:(){Navigator.pop(context);} ) ], ) ); } }전체코드입니다..
-
글쓴이글
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
- 답변은 로그인 후 가능합니다.
