Created
February 23, 2023 21:19
-
-
Save lstonussi/53c305e319a6dd9d6d2a9c11ad484ff3 to your computer and use it in GitHub Desktop.
teste1234
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return const MaterialApp( | |
title: 'Flutter Demo', | |
home: MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
const MyHomePage({Key? key, required this.title}) : super(key: key); | |
final String title; | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
DateTime selectedDate = DateTime.now(); | |
Future<void> _selectDate(BuildContext context) async { | |
final DateTime? picked = await showDatePicker( | |
context: context, | |
initialDate: selectedDate, | |
firstDate: DateTime(2015, 8), | |
lastDate: DateTime(2101)); | |
if (picked != null && picked != selectedDate) { | |
setState(() { | |
selectedDate = picked; | |
}); | |
} | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisSize: MainAxisSize.min, | |
children: <Widget>[ | |
Text("${selectedDate.toLocal()}".split(' ')[0]), | |
const SizedBox( | |
height: 20.0, | |
), | |
ElevatedButton( | |
onPressed: () { | |
Future.delayed( | |
const Duration( | |
milliseconds: 100, | |
), () { | |
_selectDate(context); | |
}); | |
}, | |
child: const Text('Select date'), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment