123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- import 'package:cs_resources/generated/assets.dart';
- import 'package:domain/entity/response/index_option_entity.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
- import 'package:get/get.dart';
- import 'package:widgets/ext/ex_widget.dart';
- import 'package:cs_resources/constants/color_constants.dart';
- import 'dart:ui';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/widgets.dart';
- import 'package:widgets/my_load_image.dart';
- import 'package:widgets/my_text_view.dart';
- import 'package:widgets/no_shadow_scroll_behavior.dart';
- import 'package:widgets/widget_export.dart';
- /*
- * 切换项目的弹窗
- */
- class SwitchProjectDialog extends StatefulWidget {
- final List<IndexOptionEntity> options;
- final void Function(IndexOptionEntity) confirmAction;
- final VoidCallback? cancelAction;
- SwitchProjectDialog({
- required this.options,
- required this.confirmAction,
- this.cancelAction,
- });
- @override
- _SwitchProjectDialogState createState() => _SwitchProjectDialogState();
- }
- class _SwitchProjectDialogState extends State<SwitchProjectDialog> {
- @override
- Widget build(BuildContext context) {
- return Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Container(
- width: double.infinity,
- decoration: const BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.all(Radius.circular(15)),
- ),
- child: Column(
- children: [
- MyTextView(
- "Switch Projects".tr,
- fontSize: 19,
- isFontMedium: true,
- textColor: ColorConstants.black,
- marginTop: 15,
- marginBottom: 15,
- ),
- Scrollbar(
- child: ScrollConfiguration(
- behavior: NoShadowScrollBehavior(),
- child: SingleChildScrollView(
- child: Column(
- children: widget.options.map<Widget>((IndexOptionEntity option) {
- return InkWell(
- onTap: () {
- // 清除其他选项的 checked 状态
- for (var opt in widget.options) {
- opt.checked = null; // 清除所有选项的 checked 状态
- }
- option.checked = 'checked'; // 选中当前选项
- setState(() {}); // 刷新页面
- },
- child: Row(
- mainAxisSize: MainAxisSize.max,
- children: [
- MyTextView(
- option.txt ?? "",
- fontSize: 15,
- isFontRegular: true,
- textColor: ColorConstants.black33,
- ).expanded(),
- option.checked == "checked"
- ? const MyAssetImage(Assets.cptAuthCheckedIcon, width: 20.5, height: 20.5)
- : const MyAssetImage(Assets.cptAuthUncheckedIcon, width: 20.5, height: 20.5)
- ],
- ).paddingOnly(top: 12, bottom: 12, left: 20, right: 20),
- );
- }).toList(),
- ),
- ),
- ),
- ).constrained(maxHeight: 210),
- Container(
- margin: const EdgeInsets.only(top: 25),
- color: const Color(0XFFCECECE),
- height: 0.5,
- ),
- Row(
- children: [
- Expanded(
- flex: 1,
- child: InkWell(
- onTap: () {
- onCancel();
- widget.cancelAction?.call();
- },
- child: MyTextView(
- "Cancel".tr,
- fontSize: 17.5,
- isFontMedium: true,
- textAlign: TextAlign.center,
- textColor: const Color(0XFF0085C4),
- cornerRadius: 3,
- borderWidth: 1,
- ),
- ),
- ),
- Container(
- color: const Color(0xff09141F).withOpacity(0.13),
- width: 0.5,
- ),
- Expanded(
- flex: 1,
- child: InkWell(
- onTap: () async {
- onCancel();
- // 找到被选中的选项并触发确认操作
- final selectedOption = widget.options.firstWhereOrNull((opt) => opt.checked == 'checked');
- if (selectedOption != null) {
- widget.confirmAction(selectedOption);
- }
- },
- child: MyTextView(
- "Confirm".tr,
- marginLeft: 10,
- fontSize: 17.5,
- isFontMedium: true,
- textAlign: TextAlign.center,
- textColor: const Color(0XFF0085C4),
- cornerRadius: 3,
- ),
- ),
- ),
- ],
- ).constrained(height: 46),
- ],
- ),
- ),
- ],
- ).constrained(width: 295);
- }
- // 取消弹框
- void onCancel() async {
- SmartDialog.dismiss();
- }
- }
|