반응형
코드 작성
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'TextField 예제',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: TextFieldExample(),
);
}
}
class TextFieldExample extends StatefulWidget {
@override
_TextFieldExampleState createState() => _TextFieldExampleState();
}
class _TextFieldExampleState extends State<TextFieldExample> {
String _enteredText = '';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('TextField 예제'),
),
body: Padding(
padding: EdgeInsets.all(20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
onChanged: (value) {
// TextField 내용이 변경될 때마다 호출되는 콜백 함수
setState(() {
_enteredText = value;
});
},
decoration: InputDecoration(
labelText: '입력하세요', // 힌트 텍스트
border: OutlineInputBorder(), // 텍스트 필드의 외곽선 스타일
),
),
SizedBox(height: 20.0),
Text(
'입력된 텍스트: $_enteredText',
style: TextStyle(fontSize: 18.0),
),
],
),
),
);
}
}
반응형
'개발 > Flutter' 카테고리의 다른 글
Flutter 플러터 Rest Api 호출 통신 간단 구현 (0) | 2024.03.16 |
---|---|
Flutter 플러터 음악 앱 만들기 Music (0) | 2024.03.15 |
Flutter 플러터 날씨 앱 간단 구현 Weather (0) | 2024.03.15 |
플러터 Flutter 스크롤 뷰 간단 구현 Scroll View (0) | 2023.11.28 |
플러터 Flutter 스톱워치 간단 구현 Stopwatch (0) | 2023.05.30 |
플러터 Flutter run : arch -x86_64 sudo gem install ffi 에러 (0) | 2023.04.01 |
플러터 Flutter Cannot find xcode build 에러가 뜰경우 (0) | 2023.04.01 |
플러터 Flutter 콘솔 유용한 명령어 모음 VSCode Console (0) | 2023.03.31 |
댓글