#
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
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
 
class SelectBox extends StatefulWidget {
  const SelectBox({super.key});
 
  @override
  State<SelectBox> createState() => _SelectBoxState();
}
 
class _SelectBoxState extends State<SelectBox> {
  String? _selectedValue = '订单号'; // 存储选中的值
  final List<String> _options = ['订单号', '物料号', '物料名',]; // 下拉框选项
 
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 0.0),
      child: PopupMenuButton<String>(
        onSelected: (String newValue) {
          setState(() {
            _selectedValue = newValue; // 更新选中的值
          });
        },
        itemBuilder: (BuildContext context) {
          return _options.map<PopupMenuItem<String>>((String value) {
            return PopupMenuItem<String>(
              value: value, // 下拉框选项的值
              child: Text(value, style: TextStyle(color: Colors.black54)), // 下拉框选项的显示
            );
          }).toList();
        },
        offset: Offset(-10, 45), // 调整下拉窗口的位置
        color: Colors.grey[300],
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Text(_selectedValue ?? '', style: TextStyle(color: Colors.black)), // 显示当前选中的值
            Icon(Icons.arrow_drop_down), // 添加一个下拉箭头图标
          ],
        ),
      ),
    );
  }
}