123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- import 'package:flutter/material.dart';
- import 'package:lszlgl/base/base_lifecycle_state.dart';
- class QyPopWidget extends StatefulWidget {
- final List pTitleList;
- final String otherStr;
- final Function(String nameStr, String otherStr) pTitleCallBack;
- const QyPopWidget(
- {super.key, required this.pTitleList, required this.otherStr, required this.pTitleCallBack});
- @override
- State<QyPopWidget> createState() => _QyPopWidgetState();
- }
- class _QyPopWidgetState extends State<QyPopWidget> {
- late TextEditingController ctrl;
- final ScrollController sctrl = ScrollController();
- @override
- void initState() {
- super.initState();
- ctrl = TextEditingController(text: widget.otherStr); // 赋值
- }
- @override
- Widget build(BuildContext context) {
- return PopScope(
- canPop: false, // 关闭系统返回,防止选中数据出错
- child: GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () {
- FocusManager.instance.primaryFocus?.unfocus();
- },
- child: SafeArea(
- child: SingleChildScrollView(
- controller: sctrl,
- padding: EdgeInsets.fromLTRB(12, 22, 12, MediaQuery.of(context).viewInsets.bottom),
- child: Column(
- mainAxisSize: MainAxisSize.min, //
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: [
- const Text(
- '请选择或填写扦样陪同人员(最多2人)',
- style: TextStyle(fontSize: 15),
- textAlign: TextAlign.center,
- ),
- const SizedBox(height: 16),
- Wrap(
- spacing: 10,
- children: List.generate(
- widget.pTitleList.length,
- (i) => ActionChip(
- backgroundColor: Colors.grey[200],
- padding: const EdgeInsets.all(6),
- side: BorderSide.none,
- shape: const RoundedRectangleBorder(
- borderRadius: BorderRadius.all(Radius.circular(18))),
- label: Text(
- widget.pTitleList[i].name,
- style: widget.pTitleList[i].isChose
- ? const TextStyle(fontSize: 14, color: Color(0xFF25A6EE))
- : const TextStyle(fontSize: 14, color: Colors.grey),
- ),
- onPressed: () {
- setState(() {
- widget.pTitleList[i].isChose = !widget.pTitleList[i].isChose;
- });
- })),
- ),
- const SizedBox(height: 12),
- TextField(
- controller: ctrl,
- style: const TextStyle(fontSize: 14),
- decoration: const InputDecoration(
- border: InputBorder.none,
- icon: Text('其他陪同人员:'),
- hintText: '多人请用逗号隔开',
- isDense: true),
- onTap: () {
- Future.delayed(const Duration(milliseconds: 600), () {
- sctrl.animateTo(
- sctrl.position.maxScrollExtent,
- duration: const Duration(milliseconds: 400),
- curve: Curves.easeOut,
- );
- });
- },
- ),
- const Divider(color: Color(0xFFE7E7E7), height: 8, thickness: 1),
- const SizedBox(height: 12),
- TextButton(
- style: ButtonStyle(
- backgroundColor: WidgetStateProperty.all(const Color(0xFF25A6EE)),
- foregroundColor: WidgetStateProperty.all(Colors.white),
- ),
- onPressed: () {
- String finalVal = '';
- for (OtherPeopleModel model in widget.pTitleList) {
- if (model.isChose) {
- finalVal = '$finalVal${model.name},';
- }
- }
- String inputVal = ctrl.text;
- if (inputVal.isNotEmpty) {
- List<String> result = inputVal.split(RegExp(r'[,,.。;;\s]'));
- result.removeWhere((val) => val == '');
- inputVal = result.join(',');
- if (inputVal.isNotEmpty) {
- // 判断只输入符号出现问题
- finalVal = '$finalVal$inputVal,';
- }
- }
- FocusManager.instance.primaryFocus?.unfocus();
- if (finalVal.isNotEmpty) {
- String vals = finalVal.substring(0, finalVal.length - 1);
- List<String> li = vals.split(',');
- if (li.length > 2) {
- MyNavigator.showToast('最多两个陪同人员');
- return;
- }
- widget.pTitleCallBack.call(vals, inputVal);
- } else {
- // 输入为空 选择为空
- widget.pTitleCallBack.call('', inputVal);
- }
- Navigator.pop(context);
- },
- child: const Text('确 定')),
- ],
- )),
- ),
- ),
- );
- }
- }
- class OtherPeopleModel {
- String? name;
- bool isChose;
- OtherPeopleModel({this.name, this.isChose = false});
- }
|