/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2022-02-23 14:23:37
 * @LastEditTime : 2023-03-29 17:56:07
 * @Description  : Do not edit
 */
import 'package:app_package/app_package.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

class WisDynamicMenuGrid extends StatelessWidget {
  const WisDynamicMenuGrid({
    Key? key,
    this.title,
    this.list,
    this.type,
    this.toRoutes,
  }) : super(key: key);
  final String? title;
  final List? list;
  final String? type;
  final Function(dynamic item, dynamic type)? toRoutes;
  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return WisCard(
      isSliver: false,
      elevation: 0,
      margin: EdgeInsets.only(
        left: 15.pt,
        right: 15.pt,
        bottom: 10.pt,
      ),
      child: Wisdom.column(
        margin: EdgeInsets.only(bottom: 8.pt),
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          Wisdom.row(
            padding: EdgeInsets.only(top: 15.pt, left: 15.pt),
            children: <Widget>[
              // WisActiveness.vertical(borderRadius: BorderRadius.circular(0)),
              WisText(
                '$title',
                color: colorScheme.mainTitle,
                weight: FontWeight.w600,
                size: 17.pt,
                overflow: TextOverflow.ellipsis,
              ).asFlexible(flex: 1),
            ],
          ),
          if (list == null || list!.length == 0)
            Padding(
              padding: EdgeInsets.symmetric(vertical: 30.pt),
              child: Text(
                '暂无数据',
                textAlign: TextAlign.center,
                style: TextStyle(color: colorScheme.minor),
              ),
            )
          else
            Wrap(
              alignment: WrapAlignment.start,
              children: <Widget>[
                for (var item in list!)
                  Container(
                    width: 85.pt,
                    margin: EdgeInsets.symmetric(vertical: 6.pt),
                    child: Wisdom.column(
                      onTap: () => toRoutes!(item, type),
                      padding: EdgeInsets.all(4.pt),
                      children: <Widget>[
                        WImage.network(
                          AppParseUtil.image(item?.icon),
                          width: 44.pt,
                          height: 44.pt,
                        ),
                        SizedBox(height: 5.pt),
                        WisText(
                          '${item?.name ?? '--'}',
                          size: 12.pt,
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ],
                    ),
                  ),
              ],
            ),
        ],
      ),
    );
  }
}
