#
whycq
2025-03-03 6a90c5bde0facc8330ce4c7c7d89292717b7ac65
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
 
import 'menu_item.dart';
 
class MenuCard extends StatelessWidget {
  final String title;
  final List<MenuItem> children;
 
  const MenuCard({
    super.key,
    required this.title,
    required this.children,
  });
 
  @override
  Widget build(BuildContext context) {
 
    // 定义文本样式
    TextStyle textStyle = TextStyle(fontSize: 24,color: Colors.black87);
 
    // 使用 TextPainter 计算文本的高度
    TextPainter textPainter = TextPainter(
      text: TextSpan(text: '自定义标题', style: textStyle),
      textDirection: TextDirection.ltr,
    );
    textPainter.layout();
 
    return Container(
      margin: EdgeInsets.all(10),
      decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.circular(20)),
      constraints: BoxConstraints(minWidth: double.infinity,minHeight: 100),
      child: Column(
        children: [
          Container(
            margin: EdgeInsets.all(5),
            padding: EdgeInsets.all(5),
            constraints: BoxConstraints(
              minWidth: double.infinity,
              minHeight: 20
            ),
            child: Row(
              children: [
                Container(
                  decoration: BoxDecoration(
                    color: Colors.blue,
                    borderRadius: BorderRadius.circular(10)
                  ),
                  height: (textPainter.height-5), // 装饰块的高度与文本高度相同
                  width: 8,
                  
                ), // 标题左侧装饰块,
                SizedBox(width: 10,),
                Text(title,style: textStyle)
 
              ],
            )
          ),
          GridView(
            shrinkWrap: true, // 使 GridView 的高度适应子部件
            physics: NeverScrollableScrollPhysics(), // 禁用滚动
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 3, childAspectRatio: 1.0),
            children: children,
          ),
        ],
      )
    );
  }
}