123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
- import '../my_text_view.dart';
- import '../utils/dark_theme_util.dart';
- import 'package:cs_resources/constants/color_constants.dart';
- class OptionPickerUtil {
- static void showCupertinoOptionPicker({
- required List<String> items,
- required Function(List<String>, int) onPickerChanged,
- int? initialSelectIndex = 0,
- String? title,
- String? confirmTextStr,
- String? cancelTextStr,
- Function()? onReset,
- }) {
- SmartDialog.show(
- usePenetrate: false,
- tag: 'data_picker',
- maskColor: Colors.black.withOpacity(0.4),
- alignment: Alignment.bottomCenter,
- builder: (BuildContext context) {
- return Container(
- height: 280,
- decoration: BoxDecoration(
- color: DarkThemeUtil.multiColors(context, Colors.white, darkColor: ColorConstants.darkBlackItem),
- borderRadius: const BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20)),
- ),
- child: Column(
- children: [
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- CupertinoButton(
- onPressed: onReset ??
- () {
- SmartDialog.dismiss(tag: 'data_picker');
- },
- child: Text(
- cancelTextStr ?? 'Cancel',
- style: const TextStyle(
- fontSize: 16,
- fontWeight: FontWeight.w600,
- color: ColorConstants.appBlue,
- ),
- ),
- ),
- Text(
- title ?? "",
- style: TextStyle(
- fontSize: 18,
- fontWeight: FontWeight.w500,
- color: DarkThemeUtil.multiColors(context, Colors.black, darkColor: Colors.white),
- ),
- ),
- CupertinoButton(
- child: Text(
- confirmTextStr ?? 'Confirm',
- style: const TextStyle(
- fontSize: 16,
- fontWeight: FontWeight.w600,
- color: ColorConstants.appBlue,
- ),
- ),
- onPressed: () {
- SmartDialog.dismiss(tag: 'data_picker');
- // 将选中的值通过回调函数传递出去
- onPickerChanged(items, initialSelectIndex!);
- },
- ),
- ],
- ),
- const Divider(color: const Color(0x4dd9d9d9), height: 0.5),
- Expanded(
- child: Container(
- alignment: Alignment.center,
- child: CupertinoPicker(
- scrollController: FixedExtentScrollController(initialItem: initialSelectIndex ?? 0),
- itemExtent: 45,
- diameterRatio: 1,
- selectionOverlay: const CupertinoPickerDefaultSelectionOverlay(
- capStartEdge: false,
- capEndEdge: false,
- ),
- onSelectedItemChanged: (int value) {
- initialSelectIndex = value;
- },
- children: items
- .map((item) => Container(
- alignment: Alignment.center,
- child: MyTextView(
- item.toString(),
- textAlign: TextAlign.center,
- textColor: DarkThemeUtil.multiColors(
- context,
- const Color(0XFF404A5B),
- darkColor: Colors.white,
- ),
- fontSize: 16,
- isFontBold: true,
- ),
- ))
- .toList(),
- ),
- )),
- ],
- ),
- );
- },
- );
- }
- }
|