반응형
showDatePicker 예제
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'data picker',
theme:ThemeData(
primarySwatch: Colors.indigo
),
home:MainPage()
);
}
}
class MainPage extends StatefulWidget {
const MainPage({Key? key}) : super(key: key);
@override
State<MainPage> createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
DateTime? _selectedDate;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Test Application"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(onPressed: (){
showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2020),
lastDate: DateTime(2023))
.then((dateTime){
setState((){
_selectedDate = dateTime;
});
});
}, child: const Text("날짜선택")),
Text('결과 : ${_selectedDate??''}')
],
),
)
);
}
}
style="width:100%; height:700px" (스타일이 사라져서 임시로 해놓음)
'til' 카테고리의 다른 글
new Day3 (위젯 사이에 공간을 주는 방법들) (0) | 2022.06.13 |
---|---|
new Day2 (BottomNavigationBar 사용법) (0) | 2022.06.10 |
day26 (0) | 2022.01.18 |
day25 (0) | 2022.01.14 |
day 24 (0) | 2022.01.13 |