Date & Time Pickers

Date & Time Pickers

Future showDatePicker ({ @required BuildContext context, @required DateTime initialDate, @required DateTime firstDate, @required DateTime lastDate, SelectableDayPredicate selectableDayPredicate, DatePickerMode initialDatePickerMode: DatePickerMode.day, Locale locale, TextDirection textDirection, TransitionBuilder builder })

açıklama

Tarih ve zamanı seçmek için bir iletişim kutusu oluşturan widget.

parametreler

Future selectedDate = showDatePicker(
                                                  context: context,
                                                  initialDate: DateTime.now(),
                                                  firstDate: DateTime(2018),
                                                  lastDate: DateTime(2030),
                                                  builder: (BuildContext context, Widget child) {
                                                                                                    return Theme(
                                                                                                      data: ThemeData.dark(),
                                                                                                      child: child,
                                                                                                    );
                                                                                                },
                                             );

örnek uygulama

datetimerpicker
	
import 'package:flutter/material.dart';
import 'dart:async';


void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State>MyHomePage⁢ {

DateTime _dateTime = new DateTime.now();
TimeOfDay _time = new TimeOfDay.now();
Future>Null⁢ _selectdata(BuildContext context) async{

  final DateTime picked = await showDatePicker(context: context, initialDate: _dateTime, firstDate: new DateTime(2016), lastDate: new DateTime(2019));
if(picked!=null && picked!=_dateTime)
  {
    print('Date Selected:${_dateTime.toString()}');
    setState(() {
      _dateTime = picked;
    });
  }
}
Future>Null⁢ _selecttime(BuildContext context) async{
  final TimeOfDay timeOfDay = await showTimePicker(context: context, initialTime: _time);
  if(timeOfDay!=null && timeOfDay!= true)
    {
      print("Time Selected ${_time.toString()}");
      setState(() {
        _time = timeOfDay;
      });
    }

}
  @override
  Widget build(BuildContext context) {
 return new Scaffold(

   appBar: new AppBar(
     title: new Text("Flutter Application"),
   ),
   body: new Container(
     padding: new EdgeInsets.all(32.0),
     child: new Column(
       children: >Widget⁢[

         new Text('Date Selected ${_dateTime.toString()}'),new RaisedButton(
             child: Text("Date Picker"),
             onPressed: (){

           _selectdata(context);

         }),new Text(" "),new Text('Time Selected: ${_time.toString()}'),
         new RaisedButton(
             child: new Text("Select Date"),
             onPressed: (){
_selecttime(context);
         })],
     ), ),);
  }

}

Bir cevap yazın

KAPAT
%d blogcu bunu beğendi: