flutter 生成单选组件

server/2024/10/21 15:28:50/

一、效果图

在这里插入图片描述

二、主要代码

import 'package:company_manage_flutter/xcClass/dicDataProp.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';class CheckListWidget extends StatefulWidget {final List<Map<String, dynamic>> list;final Function? onChanged;final DicDataProp props;Map<String, dynamic>? initValue;CheckListWidget({super.key,required this.list,this.onChanged,this.props = const DicDataProp(),this.initValue});@overrideState<CheckListWidget> createState() => CheckListWidgetState();
}class CheckListWidgetState extends State<CheckListWidget> {RxMap<String, dynamic> selected = <String, dynamic>{}.obs;@overridevoid initState() {// TODO: implement initStatesuper.initState();selected.value = widget.initValue ?? {};}@overrideWidget build(BuildContext context) {return buildCheckList(widget.list, widget.onChanged, props: widget.props);}void test() {print('test-组件内的方法');}//单选列表Widget buildCheckList(List<Map<String, dynamic>> list, Function? onChanged,{DicDataProp? props}) {String label = props?.label ?? 'label';String value = props?.value ?? 'value';return Obx(() => Container(width: Get.width,child: Column(children: list.asMap().entries.map((entry) {int index = entry.key;dynamic item = entry.value;return Column(children: [GestureDetector(onTap: () {selected?.value = item;if (onChanged != null) {onChanged(item);}},child: Container(width: Get.width,decoration: BoxDecoration(color: Colors.blue.withOpacity(0),),padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 16),child: Row(children: [Icon((selected?.value[value] ?? '') == item[value]? Icons.check_circle: Icons.circle_outlined,size: 22,color:(selected?.value[value] ?? '') == item[value]? Color.fromRGBO(50, 73, 223, 1): Color.fromRGBO(21, 23, 30, 0.40)),SizedBox(width: 6),Text(item[label] ?? "",style: TextStyle(fontSize: 16,),),],),)),Divider(height: 1,color: index + 1 == list.length? Color.fromRGBO(128, 130, 145, 0): Color.fromRGBO(128, 130, 145, 0.20),),],);}).toList(),)));}
}

三、使用

//CheckListWidgetState 不能已下划线开头,因为_开头是私有的,不能在其他文件中访问final checkListWidgetKey = GlobalKey<CheckListWidgetState>();CheckListWidget(key: checkListWidgetKey,list: bottomSheetList,onChanged: (value) {print("CheckListWidget:${value}");},initValue: const {'id': '18', 'name': '仓库1'},props: DicDataProp(label: 'name', value: 'id'),),buildButtonWidget('调用组件的方法、获取值', onPressed: () {print('调用组件的方法、获取值 = ${checkListWidgetKey.currentState?.selected}');checkListWidgetKey.currentState?.test();}),

http://www.ppmy.cn/server/30877.html

相关文章

人大金仓数据库的数据分析的方法和工具

人大金仓数据库作为中国社会科学院经济研究所主办的重要数据平台&#xff0c;不仅提供丰富的经济学研究成果&#xff0c;还支持用户进行数据分析和挖掘&#xff0c;以发现数据中的规律和趋势。在以下的论述中&#xff0c;我将深入探讨人大金仓数据库的数据分析方法和工具。 数…

苹果CEO对未来一代人工智能投资持乐观态度

尽管在动荡的第二季度&#xff0c;苹果的收入和iPhone销量有所下降&#xff0c;但其新兴的人工智能技术可能会带来急需的提振。 在5月2日的电话财报会议上&#xff0c;苹果公布季度收入为908亿美元&#xff0c;比去年下降4%。iPhone的收入也下降了10%&#xff0c;至460亿美元。…

前端页面单元测试最佳策略:全面涵盖逻辑、组件、流程、UI及性能优化测试,全面保障软件应用的质量

页面级别的测试要求我们从更宏观的角度审视应用&#xff0c;不仅关注单个组件的正确性&#xff0c;还要确保组件间的协作无误&#xff0c;以及用户在应用中的完整体验。通过集成测试、E2E测试和场景测试&#xff0c;我们可以更全面地覆盖应用的各种使用情况&#xff0c;提高软件…

使用QT完成如图的游戏登录界面 使用信号和槽完成密文明文密码转换,重置账号和密码,登录校验 详细代码在主页下载

头文件: #ifndef LOGINWIDGET_H #define LOGINWIDGET_H #include <QLineEdit> #include <QPushButton> #include <QWidget> class LoginWidget : public QWidget {Q_OBJECT public: LoginWidget(QWidget *parent = 0); ~LoginWidget(); public slots: …

解码Starknet Verifier:深入逆向工程之旅

1. 引言 Sandstorm为&#xff1a; 能提交独立proof给StarkWare的Ethereum Verifier&#xff0c;的首个开源的STARK prover。 开源代码见&#xff1a; https://github.com/andrewmilson/sandstorm&#xff08;Rust&#xff09; L2Beat 提供了以太坊上Starknet的合约架构图&…

06_电子设计教程基础篇(学习视频推荐)

文章目录 前言一、基础视频1、电路原理3、模电4、高频电子线路5、电力电子技术6、数学物理方法7、电磁场与电磁波8、信号系统9、自动控制原理10、通信原理11、单片机原理 二、科普视频1、工科男孙老师2、达尔闻3、爱上半导体4、华秋商城5、JT硬件乐趣6、洋桃电子 三、教学视频1…

数据库漫谈-发展简史

数据管理最早都是开发者自行定义的&#xff0c;应用和数据管理是一体的&#xff0c;没有独立的数据管理系统。1961年为了支持阿波罗计划的执行&#xff0c;IBM开发了ICS数据库&#xff0c;这是个层次数据库&#xff0c;是最早的大型数据库。另一个巨头GE公司看到ICS的问题&…

Xamarin.Android项目使用ConstraintLayout约束布局

Xamarin.AndroidX.ConstraintLayout Xamarin.Android.Support.Constraint.Layout Xamarin.AndroidX.ConstraintLayout.Solver Xamarin.AndroidX.DataBinding.ViewBinding Xamarin.AndroidX.Legacy.Support.Core.UI Xamarin.AndroidX.Lifecycle.LiveData ![在这里插入图片描述]…