date_time_widget 0.0.4 copy "date_time_widget: ^0.0.4" to clipboard
date_time_widget: ^0.0.4 copied to clipboard

Flutter Package for Date and Time Picker.

example/lib/main.dart

import 'package:date_time_widget/Module/DatePicker/date_picker_view.dart';
import 'package:date_time_widget/TimePicker/time_picker_view.dart';
import 'package:flutter/material.dart';
import 'package:date_time_widget/shared_class.dart';
import 'package:intl/intl.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: Scaffold(
        body: HomePage(),

      ),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  String stringDate = 'SELECT DATE';
  String stringTime = 'SELECT TIME';

  void dateCallBack(value) {
    DateTime selected = value;
    setState(() {
      String formattedDate = DateFormat('dd-MMM-yyyy').format(selected);
      stringDate = '$formattedDate';
    });  }

  void hourCallBack(value) {
    setState(() {
      stringTime = '$value';
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        color: hexToColor('#358497'),
        padding: EdgeInsets.only(top: 20),
        child: SafeArea(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Container(
                color: hexToColor('#358497'),
                padding: EdgeInsets.only(left:15),
                child: Text(
                  stringDate,
                  style:
                  TextStyle(fontSize: 18, color: hexToColor('#F4A896'),fontWeight: FontWeight.bold),
                  textAlign: TextAlign.center,
                ),
                height: 30,
              ),
              DatePicker(
                  textColor: hexToColor('#F4A896'),
                  widgetBackColor: hexToColor('#F4A896'),
                  listBackColor: Color(0xffffcdd2),
                  widgetHeight: 80,
                  widgetWidth: 80,
                  containerHeight: 100,
                  containerWidth: 100,
                  expandWidth: MediaQuery.of(context).size.width,
                  dateCallBack: dateCallBack,
                  timeCallBack: null,
                  calendarType: typesofCalendar.days),
              Container(
                padding: EdgeInsets.only(left:15),
                color: hexToColor('#358497'),
                child: Text(stringTime,
                    style: TextStyle(
                        fontSize: 18, color: hexToColor('#F4A896'),fontWeight: FontWeight.bold),
                    textAlign: TextAlign.start),
                height: 30,
              ),
              TimePicker(
                  textColor: hexToColor('#F4A896'),
                  widgetBackColor: hexToColor('#F4A896'),
                  listBackColor: Colors.red,
                  widgetHeight: 80,
                  widgetWidth: 80,
                  containerHeight: 100,
                  containerWidth: 100,
                  expandWidth: MediaQuery.of(context).size.width,
                  dateCallBack: null,
                  timeCallBack: hourCallBack,
                  calendarType: typesofCalendar.hours)
            ],
          ),
        ));
  }
}

Color hexToColor(String hexString, {String alphaChannel = 'FF'}) {
  return Color(int.parse(hexString.replaceFirst('#', '0x$alphaChannel')));
}
2
likes
30
points
12
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter Package for Date and Time Picker.

Homepage

License

MIT (license)

Dependencies

animated_clipper, cupertino_icons, flutter, infinite_listview, intl, local_hero

More

Packages that depend on date_time_widget