/*
 * @Author: XianKaiQun
 * @LastEditors  : WuWei
 * @Date: 2020-10-28 10:33:23
 * @LastEditTime : 2023-05-25 15:51:03
 */

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

import '../../assets.gen.dart';

///附件选择
class WFAccessoryPicker extends StatelessWidget {
  const WFAccessoryPicker({
    Key? key,
    this.title,
    this.isRequired = false,
    this.onChanged,
    this.initialDate,
  }) : super(key: key);
  final Widget? title;

  ///是否必须
  final bool isRequired;
  final DateTime? initialDate;
  final void Function(DateTime datetime)? onChanged;

  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    // DateTime _initialDate = initialDate;
    final images = [
      for (var i = 0; i < 1; i++)
        CachedNetworkImageProvider(
            'https://wy-test.huiguanjia.cn/9ad134a361f8d778/file/images//401787958742806528'),
    ];
    return WisFormLayoutComponent(
      title: title,
      isRequired: isRequired,
      axis: Axis.horizontal,
      child: StatefulBuilder(
        builder: (BuildContext context, setState) {
          return Column(
            crossAxisAlignment: CrossAxisAlignment.end,
            children: [
              Wisdom.row(
                onTap: () {},
                mainAxisSize: MainAxisSize.min,
                height: 44.pt,
                children: [
                  Image(
                    image: AssetList.$accessoryUpload_png_image,
                    height: 12.pt,
                  ),
                  Text(
                    ' 上传附件图片',
                    style: TextStyle(
                      color: colorScheme.primary,
                      fontSize: 13.pt,
                    ),
                  ),
                ],
              ),
              Wisdom.wrap(
                runSpacing: 10.pt,
                spacing: 10.pt,
                runAlignment: WrapAlignment.end,
                crossAxisAlignment: WrapCrossAlignment.end,
                wrapAlignment: WrapAlignment.end,
                padding: EdgeInsets.symmetric(vertical: 10.pt),
                children: [
                  for (var i = 0; i < images.length; i++)
                    Wisdom.stack(
                      width: 63.pt,
                      height: 63.pt,
                      clipBehavior: Clip.none,
                      children: [
                        Wisdom(
                          onTap: () => WisPhotoViewUtil.show(images, i),
                          padding: EdgeInsets.only(right: 5.pt, top: 5.pt),
                          child: WImage(
                            image: images[i],
                            borderRadius: BorderRadius.circular(4.pt),
                            fit: BoxFit.cover,
                          ),
                        ),
                        Positioned(
                          right: 0,
                          top: 0,
                          child: WFClose(
                            onTap: () {},
                            backgroundColor: Colors.black.withOpacity(0.6),
                            color: Colors.white,
                          ),
                        ),
                      ],
                    ),
                ],
              ),
            ],
          );
        },
      ),
    );
  }
}
