Picker In Flutter

Picker In Flutter :

Screenshot :

Picker In Flutter
Picker In Flutter
Picker In Flutter
Picker In Flutter
Picker In Flutter
Picker In Flutter
Picker In Flutter

Picker In Flutter

main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: "Flutter Tutorial",
      theme: ThemeData.light(),
      home: PickerWidget(),
    );
  }
}

class PickerWidget extends StatefulWidget {
  @override
  PickerWidgetState createState() => new PickerWidgetState();
}

class PickerWidgetState extends State<PickerWidget> {
  List<String> titles = [
    'Picker',
    'DayPicker',
    'MonthPicker',
    'YearPicker',
    'CupertinoPicker',
    'CupertinoDatePicker',
    'CupertinoTimerPicker',
  ];

  DateTime dayPicker = DateTime.now();
  Duration m = Duration(minutes: 1);

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Picker'),
      ),
      body: ListView.builder(
        itemCount: titles.length,
        itemBuilder: (context, index) {
          return ListTile(
              dense: true,
              title: Text(titles[index]),
              onTap: () {
                switch (index) {
                  case 0:
                    showDatePicker(
                      context: context,
                      initialDate: DateTime.now(),
                      firstDate: DateTime.utc(1990, 1, 1),
                      lastDate: DateTime.utc(2100, 12, 31),
                    );
                    break;
                  case 1:
                    showModalBottomSheet(
                      context: context,
                      builder: (context) {
                        return DayPicker(
                            selectedDate: dayPicker,
                            currentDate: DateTime.now(),
                            onChanged: (time) {
                              Navigator.of(context).pop();
                              setState(() {
                                dayPicker = time;
                              });
                            },
                            firstDate: DateTime.utc(
                              DateTime.now().year,
                              DateTime.now().month,
                              3,
                            ),
                            lastDate: DateTime.utc(
                              DateTime.now().year,
                              DateTime.now().month,
                              22,
                            ),
                            selectableDayPredicate: (time) {
                              return true;
                            },
                            displayedMonth: DateTime.now());
                      },
                    );
                    break;
                  case 2:
                    showModalBottomSheet(
                        context: context,
                        builder: (context) {
                          return MonthPicker(
                            selectedDate: dayPicker,
                            onChanged: (time) {
                              Navigator.of(context).pop();
                              setState(() {
                                dayPicker = time;
                              });
                            },
                            firstDate: DateTime.utc(2000, 1),
                            lastDate: DateTime.utc(2100, 12),
                          );
                        });
                    break;
                  case 3:
                    showModalBottomSheet(
                        context: context,
                        builder: (context) {
                          return YearPicker(
                            selectedDate: dayPicker,
                            onChanged: (time) {
                              Navigator.of(context).pop();
                              setState(() {
                                dayPicker = time;
                              });
                            },
                            firstDate: DateTime.utc(2000, 1),
                            lastDate: DateTime.utc(2100, 12),
                          );
                        });
                    break;
                  case 4:
                    showModalBottomSheet(
                        context: context,
                        builder: (context) {
                          return CupertinoPicker(
                              itemExtent: 40.0,
                              onSelectedItemChanged: (index) {},
                              diameterRatio: 360.0,
                              useMagnifier: true,
                              magnification: 1.0,
                              looping: true,
                              backgroundColor: Colors.white,
                              offAxisFraction: 100.0,
                              children: [
                                Text('Item 1'),
                                Text('Item 2'),
                                Text('Item 3'),
                                Text('Item 4'),
                                Text('Item 5'),
                                Text('Item 6'),
                                Text('Item 7'),
                                Text('Item 8'),
                                Text('Item 9'),
                                Text('Item 10'),
                              ]);
                        });
                    break;
                  case 5:
                    showModalBottomSheet(
                        context: context,
                        builder: (context) {
                          return CupertinoDatePicker(
                              initialDateTime: DateTime.now(),
                              minimumYear: 1900,
                              use24hFormat: true,
                              mode: CupertinoDatePickerMode.date,
                              onDateTimeChanged: (time) {
                                setState(() {
                                  dayPicker = time;
                                });
                              });
                        });
                    break;
                  case 6:
                    showModalBottomSheet(
                        context: context,
                        builder: (context) {
                          return CupertinoTimerPicker(
                            onTimerDurationChanged: (duration) {},
                            initialTimerDuration: m,
                          );
                        });
                    break;
                }
              });
        },
      ),
    );
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  void didUpdateWidget(PickerWidget oldWidget) {
    super.didUpdateWidget(oldWidget);
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
  }
}

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in