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

class ActionDateAlert extends StatefulWidget {
  final String title;
  final TextStyle normalStyle;
  final TextStyle selectedStyle;

  const ActionDateAlert({
    Key key,
    this.title,
    this.normalStyle,
    this.selectedStyle,
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() => _ActionDateAlert();
}

class _ActionDateAlert extends State<ActionDateAlert> {
  DateTime _dateTime = DateTime.now();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: GestureDetector(
        child: Column(
          children: <Widget>[
            Expanded(
              child: Container(),
            ),
            Container(
              width: double.infinity,
              height: 250,
              margin: EdgeInsets.all(0),
              decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(10),
                      topRight: Radius.circular(10))),
              child: Column(
                children: <Widget>[
                  widget.title == null || widget.title == ''
                      ? Container()
                      : Container(
                          height: 44,
                          child: Row(
                            children: <Widget>[
                              FlatButton(
                                child: Text('取消'),
                                onPressed: () {
                                  Navigator.pop(context);
                                },
                              ),
                              Expanded(
                                child: Center(
                                  child: Text(
                                    widget.title,
                                    style: TextStyle(
                                        fontSize: 13,
                                        color: Colors.black.withAlpha(180)),
                                  ),
                                ),
                              ),
                              FlatButton(
                                child: Text(
                                  '完成',
                                  style: TextStyle(
                                      color: HexColor.fromHex('#E52425')),
                                ),
                                onPressed: () {
                                  Navigator.pop(context, _dateTime);
                                },
                              ),
                            ],
                          )),
                  Expanded(
                    child: _createContent(context),
                  )
                ],
              ),
            ),
          ],
        ),
        onTap: () {
          Navigator.pop(context);
        },
      ),
    );
  }

  Widget _createContent(BuildContext context) {
    return DatePickerWidget(
      initialDateTime: _dateTime,
      onChange: (dataTime, list) {
        _dateTime = dataTime;
      },
      pickerTheme: DateTimePickerTheme(
        pickerHeight: 180,
        title: Container(),
      ),
    );
  }
}
