728x90
반응형
728x170
▶ main.dart
import 'package:flutter/material.dart';
void main() => runApp(TestApplication());
class TestApplication extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Test Application',
home: Scaffold(
appBar: AppBar(
title: Text('Test Application'),
),
body: MainPage(),
),
);
}
}
class MainPage extends StatefulWidget {
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFormField(
validator: (value) {
if (value.isEmpty) {
return '주소를 입력해 주시기 바랍니다.';
}
return null;
},
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: RaisedButton(
child: Text('검증'),
onPressed: () {
if (_formKey.currentState.validate()) {
Scaffold.of(context).showSnackBar(SnackBar(content: Text('정상적으로 입력되었습니다.')));
}
},
),
),
],
),
),
);
}
}
728x90
반응형
그리드형(광고전용)
'Flutter' 카테고리의 다른 글
[FLUTTER] BottomAppBar 클래스 사용하기 (0) | 2021.05.02 |
---|---|
[FLUTTER] Positioned 클래스 사용하기 (0) | 2021.05.02 |
[FLUTTER] 스톱워치(Stopwatch) 만들기 (0) | 2021.05.02 |
[FLUTTER] 비만도 계산기 만들기 (0) | 2021.05.01 |
[FLUTTER] Opacity 클래스 : opacity 속성을 사용해 불투명도 표시하기 (0) | 2021.05.01 |
[FLUTTER] TextFormField 클래스 : validator 속성을 사용해 입력 값 검증하기 (0) | 2021.05.01 |
[FLUTTER] Form 클래스 : 입력 값 검증하기 (0) | 2021.05.01 |
[FLUTTER] TextEditingController 클래스 사용하기 (0) | 2021.05.01 |
[FLUTTER] CarouselSlider 클래스 : 자동 스크롤 슬라이더 사용하기 (0) | 2021.04.29 |
[FLUTTER] Navigator 클래스 : pushNamed 정적 메소드를 사용해 화면 이동하기 (0) | 2021.04.27 |
댓글을 달아 주세요