uipickers 0.0.9 copy "uipickers: ^0.0.9" to clipboard
uipickers: ^0.0.9 copied to clipboard

PlatformiOS

A plugin library that exposes platform specific date, time and picker popups. It uses native iOS 14 style pickers on iOS and corresponding material pickers on other platforms.

example/lib/main.dart

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

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int selectedItem = 0;
  DateTime selectedDate = DateTime.now();
  final key1 = GlobalKey();
  final key2 = GlobalKey();
  final items = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            body: Padding(
                padding: const EdgeInsets.fromLTRB(100, 140, 20, 20),
                child: Column(children: [
                  SizedBox(
                      width: 150,
                      height: 34,
                      child: AdaptivePicker(
                          key: key1,
                          type: AdaptivePickerType.material,
                          items: items,
                          value: selectedItem,
                          dropDownItemTextColor: Colors.green,
                          onChanged: (val) {
                            setState(() {
                              selectedItem = val ?? 0;
                              selectedDate = DateTime.now()
                                  .add(Duration(days: selectedItem));
                            });
                          })),
                  const SizedBox(height: 12),
                  SizedBox(
                      width: 150,
                      height: 34,
                      child: AdaptiveDatePicker(
                        key: key2,
                        type: AdaptiveDatePickerType.material,
                        initialDate: selectedDate,
                        firstDate: DateTime.now(),
                        lastDate: DateTime.now().add(const Duration(days: 10)),
                        onChanged: (date) {
                          setState(() {
                            selectedDate = date;
                            selectedItem =
                                daysBetween(DateTime.now(), selectedDate);
                          });
                        },
                      ))
                ]))));
  }

  int daysBetween(DateTime from, DateTime to) {
    var fromD = DateTime(from.year, from.month, from.day);
    var toD = DateTime(to.year, to.month, to.day);
    return (toD.difference(fromD).inHours / 24).round();
  }
}
16
likes
130
points
4
downloads

Publisher

unverified uploader

Weekly Downloads

A plugin library that exposes platform specific date, time and picker popups. It uses native iOS 14 style pickers on iOS and corresponding material pickers on other platforms.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, intl

More

Packages that depend on uipickers

Packages that implement uipickers