wmhpicker 0.0.8 copy "wmhpicker: ^0.0.8" to clipboard
wmhpicker: ^0.0.8 copied to clipboard

Custom pickerView.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:wmhpicker/wmhpicker.dart';
import 'package:flutter/cupertino.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      debugShowCheckedModeBanner: false,
      home: homeApp(),
    );
  }
}

class homeApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<homeApp> {
  bool showView = false;
  int selectYear = 0;
  int selectMonth = 0;
  int selectDay = 0;
  String _platformVersion = 'Unknown';
  List<Map> tempData = [
    {'subDatas' : ['明天','今天','后天']},
    {'subDatas' : ['不想','想','要']},
    {'subDatas' : ['去吃饭','去玩','去打游戏']},
  ];

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await Wmhpicker.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
//      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: GestureDetector(
          child: Container(
            width: 100,
            height: 100,
            color: Colors.red,
          ),
          onTap: () {
            print(this.selectYear.toString() + this.selectMonth.toString() + this.selectDay.toString());
            var now = new DateTime.now();

            showView = true;
            showDialog<Null>(
                context: context, //BuildContext对象
                barrierDismissible: false,
                builder: (BuildContext context) {
                  return WMHPickerView(showPicker: true, pickerData: this.tempData, callBack: (item) {
                    showView = false;
                    this.selectYear = int.parse(item[0].toString());
                    this.selectMonth = int.parse(item[1].toString());
                    this.selectDay = int.parse(item[2].toString());
                    print(this.selectYear.toString() + this.selectMonth.toString() + this.selectDay.toString());
                    setState(() {

                    });
                  }, cancelBtnColor: Colors.black,
                      confirmBtnColor: Colors.black,
                      pickerBackgroundColor: Colors.white,
                      pickerTextColor: Colors.black,
                      textSize: 20.0,pickerHeight: 300,
                  isDatePicker: true,
                  minYear: 2016,
                  maxYear: now.year,
                  selectDay: this.selectDay > 0 ? this.selectDay : now.day,
                  selectMonth: this.selectMonth > 0 ? this.selectMonth : now.month,
                  selectYear: this.selectYear > 0 ? this.selectYear : now.year);
                });
          },
        ),
      ),
    );
  }
}
0
likes
15
pub points
0%
popularity

Publisher

unverified uploader

Custom pickerView.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on wmhpicker