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

class ActionSelectedAlert extends StatelessWidget {
  final String title;
  final List<String> actions;

  const ActionSelectedAlert({Key key, this.title, this.actions})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: GestureDetector(
        child: Container(
            width: double.infinity,
            // height: double.infinity,
            color: Colors.transparent,
            child: Container(
              width: double.infinity,
              // height: double.infinity,
              // color: Colors.red,
              child: Column(
                children: <Widget>[
                  Expanded(
                    child: Container(),
                  ),
                  Container(
                    width: double.infinity,
                    margin: EdgeInsets.all(0),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(10),
                            topRight: Radius.circular(10))),
                    child: Column(
                      children: <Widget>[
                        title == null || title == ''
                            ? Container()
                            : Container(
                                height: 44,
                                child: Center(
                                  child: Text(
                                    title,
                                    style: TextStyle(
                                        fontSize: 13,
                                        color: Colors.black.withAlpha(180)),
                                  ),
                                ),
                              ),
                        title == null || title == '' || actions.length == 0
                            ? Container()
                            : Container(
                                width: double.infinity,
                                height: 0.5,
                                color: HexColor.fromHex('#F2F2F2'),
                              ),
                        _createContent(context),
                        Container(
                          width: double.infinity,
                          height: 4,
                          color: HexColor.fromHex('#F2F2F2'),
                        ),
                        SafeArea(
                          child: Container(
                            width: double.infinity,
                            margin: EdgeInsets.all(0),
                            color: Colors.white,
                            height: 56,
                            child: Center(
                              child: Text(
                                '取消',
                                style: TextStyle(
                                    fontSize: 17, color: Colors.black),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            )),
        onTap: () {
          Navigator.pop(context);
        },
      ),
    );
  }

  Widget _createContent(BuildContext context) {
    List<Widget> widgets = List<Widget>();
    for (int index = 0; index < actions.length; index++) {
      int i = index;
      widgets.add(Column(
        children: <Widget>[
          GestureDetector(
            child: Container(
              color: Colors.transparent,
              height: 54,
              child: Center(
                child: Text(
                  actions[index],
                  style: TextStyle(fontSize: 17, color: Colors.black),
                ),
              ),
            ),
            onTap: () {
              print(i);
              Navigator.pop(context, i);
            },
          ),
          Container(
            width: double.infinity,
            height: 0.5,
            color: HexColor.fromHex('#F2F2F2'),
          )
        ],
      ));
    }
    return Column(children: widgets);
  }
}
