flutter_picker_view 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 71

flutter_picker_view #

A Flutter picker view like iOS UIPickerView support multiple pickers

Getting Started #

First, add flutter_picker_view as a dependency in your pubspec.yaml file.

Demo #

image

Example #

import 'package:flutter_picker_view/flutter_picker_view.dart';
enum PickerShowMode {
    AlertDialog,
    BottomSheet
}

AlertDialog #

image

BottomSheet #

image

void _showPicker() {
    PickerController pickerController = PickerController(count: 3, selectedItems: [5,2,1]);
    
    PickerViewPopup.showMode(
        PickerShowMode.AlertDialog, // AlertDialog or BottomSheet
        controller: pickerController,
        context: context,
        title: Text('AlertDialogPicker',style: TextStyle(fontSize: 14),),
        cancel: Text('cancel', style: TextStyle(color: Colors.grey),),
        onCancel: () {
            Scaffold.of(context).showSnackBar(
                SnackBar(content: Text('AlertDialogPicker.cancel'))
            );
        },
        confirm: Text('confirm', style: TextStyle(color: Colors.blue),),
        onConfirm: (controller) {
            List<int> selectedItems = [];
            selectedItems.add(controller.selectedRowAt(section: 0));
            selectedItems.add(controller.selectedRowAt(section: 1));
            selectedItems.add(controller.selectedRowAt(section: 2));

            Scaffold.of(context).showSnackBar(
                SnackBar(content: Text('AlertDialogPicker.selected:$selectedItems'))
            );
        },
        builder: (context, popup) {
            return Container(
                height: 150,
                child: popup,
            );
        },
        itemExtent: 40,
        numberofRowsAtSection: (section) {
            return 10;
        },
        itemBuilder: (section, row) {
            return Text('$row',style: TextStyle(fontSize: 12),);
        }
    );
}

Custom PickerView #

image


PickerController controller = PickerController(count: 2);

PickerView(
    itemExtent: 40,
    numberofRowsAtSection: (section) {
        return 10;
    },
    itemBuilder: (section, row) {
        if (0 == section) {
            return Padding(
                padding: EdgeInsets.only(left: 20),
                child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                        Text('$row',style: TextStyle(fontSize: 14),),
                        Icon(Icons.face)
                    ],
                ),
            );
        } else {
            return Padding(
                padding: EdgeInsets.only(right: 20),
                child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                        Text('$row',style: TextStyle(fontSize: 14),),
                        Icon(Icons.thumb_up)
                    ],
                )
            );
        }
    },
    controller: controller
)

[1.0.0] - 2019-09-26

  • dart sdk support: ">=2.1.0 <3.0.0", remove Spread elements.

[0.0.2] - 2019-09-17

  • 解决PickerController selectedItems为null时PickerVIew不显示的bug

[0.0.1] - 2019-0912

  • A Flutter picker view like iOS UIPickerView support multiple pickers

example/README.md

Example #

import 'package:flutter_picker_view/flutter_picker_view.dart';
enum PickerShowMode {
    AlertDialog,
    BottomSheet
}

AlertDialog #

image

BottomSheet #

image

void _showPicker() {
    PickerController pickerController = PickerController(count: 3, selectedItems: [5,2,1]);
    
    PickerViewPopup.showMode(
        PickerShowMode.AlertDialog, // AlertDialog or BottomSheet
        controller: pickerController,
        context: context,
        title: Text('AlertDialogPicker',style: TextStyle(fontSize: 14),),
        cancel: Text('cancel', style: TextStyle(color: Colors.grey),),
        onCancel: () {
            Scaffold.of(context).showSnackBar(
                SnackBar(content: Text('AlertDialogPicker.cancel'))
            );
        },
        confirm: Text('confirm', style: TextStyle(color: Colors.blue),),
        onConfirm: (controller) {
            List<int> selectedItems = [];
            selectedItems.add(controller.selectedRowAt(section: 0));
            selectedItems.add(controller.selectedRowAt(section: 1));
            selectedItems.add(controller.selectedRowAt(section: 2));

            Scaffold.of(context).showSnackBar(
                SnackBar(content: Text('AlertDialogPicker.selected:$selectedItems'))
            );
        },
        builder: (context, popup) {
            return Container(
                height: 150,
                child: popup,
            );
        },
        itemExtent: 40,
        numberofRowsAtSection: (section) {
            return 10;
        },
        itemBuilder: (section, row) {
            return Text('$row',style: TextStyle(fontSize: 12),);
        }
    );
}

Custom PickerView #

image


PickerController controller = PickerController(count: 2);

PickerView(
    itemExtent: 40,
    numberofRowsAtSection: (section) {
        return 10;
    },
    itemBuilder: (section, row) {
        if (0 == section) {
            return Padding(
                padding: EdgeInsets.only(left: 20),
                child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                        Text('$row',style: TextStyle(fontSize: 14),),
                        Icon(Icons.face)
                    ],
                ),
            );
        } else {
            return Padding(
                padding: EdgeInsets.only(right: 20),
                child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                        Text('$row',style: TextStyle(fontSize: 14),),
                        Icon(Icons.thumb_up)
                    ],
                )
            );
        }
    },
    controller: controller
)

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_picker_view: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_picker_view/flutter_picker_view.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
43
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

We analyzed this package on Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/flutter_picker_view.dart.

Run flutter format to format lib/flutter_picker_view.dart.

Format lib/picker_view.dart.

Run flutter format to format lib/picker_view.dart.

Format lib/picker_view_popup.dart.

Run flutter format to format lib/picker_view_popup.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test