123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'alert_dialog.dart';
- /// 小弹窗输入
- class VDialogInput extends StatelessWidget {
- /// 标题
- final String? title;
- /// 描述
- final String? description;
- /// 输入占位符
- final String? placeholder;
- /// 初始值
- final String? initialValue;
- const VDialogInput({
- super.key,
- this.title,
- this.description,
- this.placeholder,
- this.initialValue,
- });
- Future<String?> show<String>() => VAlertDialog.showDialog<String>(this);
- @override
- Widget build(BuildContext context) {
- final controller = TextEditingController(text: initialValue);
- return VAlertDialog(
- title: title,
- width: 440,
- contentPadding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
- content: _buildContent(context, controller),
- showCancel: true,
- onConfirm: () {
- Get.back(result: controller.text);
- },
- );
- }
- Widget _buildContent(
- BuildContext context,
- TextEditingController controller,
- ) {
- final children = <Widget>[];
- if (description != null) {
- children.add(
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 4),
- child: Text(
- description!,
- style: const TextStyle(color: Colors.black87, fontSize: 18),
- ),
- ),
- );
- children.add(const SizedBox(height: 8));
- } else {
- children.add(const SizedBox(height: 12));
- }
- children.add(_buildInputWidget(context, controller));
- return SingleChildScrollView(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: children,
- ),
- );
- }
- Widget _buildInputWidget(
- BuildContext context,
- TextEditingController controller,
- ) {
- const fontSize = 20.0;
- const height = 56.0;
- return SizedBox(
- height: height,
- child: TextField(
- controller: controller,
- readOnly: false,
- autofocus: true,
- style: const TextStyle(fontSize: fontSize),
- decoration: InputDecoration(
- border: const UnderlineInputBorder(
- borderRadius: BorderRadius.zero,
- borderSide: BorderSide(),
- ),
- enabledBorder: const UnderlineInputBorder(
- borderRadius: BorderRadius.zero,
- borderSide: BorderSide(
- color: Colors.black54,
- ),
- ),
- focusedBorder: UnderlineInputBorder(
- borderRadius: BorderRadius.zero,
- borderSide: BorderSide(
- color: Theme.of(context).primaryColor.withOpacity(.4),
- ),
- ),
- filled: true,
- fillColor: Colors.white,
- contentPadding: const EdgeInsets.symmetric(
- vertical: 8,
- horizontal: 8,
- ),
- hintStyle: const TextStyle(fontSize: fontSize),
- labelStyle: const TextStyle(fontSize: fontSize),
- hintText: placeholder,
- isCollapsed: true,
- ),
- onSubmitted: (value) {
- Get.back(result: value);
- },
- ),
- );
- }
- }
|