Code Monkey home page Code Monkey logo

jakebrighthr / flutter_uipickers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tzraikov/flutter_uipickers

0.0 0.0 0.0 233 KB

A flutter plugin library that exposes platform specific date, time and picker popups. It uses the native iOS 14 UIKit UIDatePicker and SwiftUI like Picker on iOS and the corresponding material pickers on other platforms.

License: MIT License

Ruby 5.17% Objective-C 1.51% Kotlin 0.27% Dart 63.06% Swift 29.99%

flutter_uipickers's Introduction

uipickers

A plugin library that exposes platform specific date, time and picker popups. It uses the native iOS 14 UIKit UIDatePicker and SwiftUI like Picker on iOS and the corresponding material pickers on other platforms.

Image 1 Image 2

Usage

First import it in your Dart code:

import 'package:uipickers/uipickers.dart';

Then select one of the following widgets:

  • AdaptiveDatePicker - Allows selecting a date or time and displays the selected date in a widget. The underlying popup is selected automatically based on the current platform.
  • AdaptivePicker - Allows selecting an item from a list of string items. The underlying popup is selected automatically based on the current platform.
  • UIDatePicker - Allows selecing a date, time, or time+date and uses a native iOS 14 style UIDatePicker component.
  • UIPicker - Allows selecting an item from a list of string items. Uses iOS native components (UIButton + UIMenu) to present SwiftUI like Picker popup.
  • MaterialDatePicker - Allows selecing a date, time, or time+date and uses the build-in material dialogs.
  • MaterialPicker - Allows selecing an item from a list of string items. Uses the build-in DropDownButton.

AdaptiveDatePicker

The AdaptiveDatePicker is used for selecting a date or time. It displays the currently selected date/time in its widget. On iOS it will use a native iOS 14 style UIDatePicker. The initialDate property sets the currently selected date, firstDate is the earliest allowable date and lastDate is the latest allowable date. The onChanged event handler is called when the user selects an item from the popup:

DateTime selectedDate = DateTime.now();
//...
AdaptiveDatePicker(
    initialDate: selectedDate,
    firstDate: DateTime.now(), 
    lastDate: DateTime.now().add(Duration(days: 10)),
    onChanged: (date) { setState(() => selectedDate = date); },
)

Warning: The size of the widget should be constrained. For example it could be wrapped inside a SizedBox:

SizedBox(width: 150, height: 34,
    child: AdaptiveDatePicker(
        //...
    )
)

In order to use the native version explicitly, just set the type property to cupertino, or replace AdaptiveDatePicker with UIDatePicker:

AdaptiveDatePicker(
    type: AdaptiveDatePickerType.cupertino,
    //...
)

The tintColor property is specific for UIDatePicker. It changes the highlighted text color:

UIDatePicker(
    tintColor: UIColors.red,
    //...
)

There are various attributes to customize, for example backgroundColor, cornerRadius, borderColor, etc.:

AdaptiveDatePicker(
    backgroundColor: Colors.blue[50]!,
    borderColor: Colors.blue[800]!,
    borderWidth: 3,
    cornerRadius: 4,
    items: items, 
    value: selectedItem, 
    onChanged: (value) { setState(() => selectedItem = value); },
);

AdaptivePicker

The AdaptivePicker widget allows automatic selection of the underlying widget implementation based on the operating system. On iOS it will use a SwiftUI like picker based on UIButton+UIMenu. The value property sets the currently selected item index, and the onChanged event handler is called when the user selects an item from the popup:

int selectedItem = 1;
var items = [ 'one', 'two', 'three' ];
//...
AdaptivePicker(
    items: items, 
    value: selectedItem, 
    onChanged: (value) { setState(() => selectedItem = value); }
)

Warning: The size of the widget should be constrained. For example it could be wrapped inside a SizedBox:

SizedBox(width: 150, height: 34,
    child: AdaptiveDatePicker(
        //...
    )
)

In order to use the native version explicitly, just set the type property to cupertino, or replace AdaptivePicker with UIPicker:

AdaptivePicker(
    type: AdaptivePickerType.cupertino,
    //...
)

There are various attributes to customize, for example backgroundColor, cornerRadius, borderColor, etc.:

UIPicker(
    backgroundColor: Colors.blue[50]!,
    borderColor: Colors.blue[800]!,
    borderWidth: 3,
    cornerRadius: 4,
    items: items, 
    value: selectedItem, 
    onChanged: (value) { setState(() => selectedItem = value); },
);

flutter_uipickers's People

Contributors

tzraikov avatar jakebrighthr avatar yukitaka13-1110 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.