角色信息添加刷新按钮

This commit is contained in:
DelLevin-Home
2026-06-29 01:13:52 +08:00
parent ede0b10b19
commit 0c7c39e641
5 changed files with 98 additions and 15 deletions

View File

@@ -105,6 +105,47 @@ class _GenreSelectorPageState extends State<GenreSelectorPage> {
}
}
void _editItem(int index, String oldValue) {
final editController = TextEditingController(text: oldValue);
showDialog<String>(
context: context,
builder: (ctx) {
final colors = Theme.of(ctx).colorScheme;
return AlertDialog(
backgroundColor: colors.surface,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
title: Text('编辑', style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600, color: colors.onSurface)),
content: TextField(
controller: editController,
autofocus: true,
style: TextStyle(fontSize: 15, color: colors.onSurface),
cursorColor: colors.primary,
decoration: InputDecoration(
filled: true,
fillColor: colors.surfaceContainerHigh,
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide.none),
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: colors.primary, width: 1)),
),
onSubmitted: (v) => Navigator.pop(ctx, v.trim()),
),
actions: [
TextButton(onPressed: () => Navigator.pop(ctx), child: Text('取消', style: TextStyle(color: colors.onSurface.withValues(alpha: 0.6)))),
ElevatedButton(
onPressed: () => Navigator.pop(ctx, editController.text.trim()),
style: ElevatedButton.styleFrom(backgroundColor: colors.primary, foregroundColor: colors.onPrimary, elevation: 0, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),
child: const Text('确定'),
),
],
);
},
).then((newValue) {
if (newValue != null && newValue.isNotEmpty && newValue != oldValue && mounted) {
setState(() => _selected[index] = newValue);
}
});
}
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
@@ -164,7 +205,8 @@ class _GenreSelectorPageState extends State<GenreSelectorPage> {
padding: EdgeInsets.zero,
itemCount: _selected.length,
itemBuilder: (_, i) {
final tag = _selected[_selected.length - 1 - i];
final idx = _selected.length - 1 - i;
final tag = _selected[idx];
return Padding(
padding: const EdgeInsets.only(bottom: 6),
child: Container(
@@ -176,10 +218,23 @@ class _GenreSelectorPageState extends State<GenreSelectorPage> {
dense: true,
contentPadding: const EdgeInsets.symmetric(horizontal: 12),
leading: Icon(Icons.check_circle, size: 20, color: colors.primary),
title: Text(tag, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: colors.onSurface)),
trailing: GestureDetector(
onTap: () => _toggle(tag),
child: Icon(Icons.close, size: 18, color: colors.onSurface.withValues(alpha: 0.35)),
title: GestureDetector(
onTap: () => _editItem(idx, tag),
child: Text(tag, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: colors.onSurface)),
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
GestureDetector(
onTap: () => _editItem(idx, tag),
child: Icon(Icons.edit, size: 16, color: colors.onSurface.withValues(alpha: 0.3)),
),
const SizedBox(width: 8),
GestureDetector(
onTap: () => _toggle(tag),
child: Icon(Icons.close, size: 18, color: colors.onSurface.withValues(alpha: 0.35)),
),
],
),
),
),

View File

@@ -1,11 +1,12 @@
import 'package:flutter/material.dart';
/// 右侧滑入文本输入弹窗(单行编辑用,如影视名称、书籍名称)
/// 右侧滑入文本输入弹窗(单行/多行编辑用,如影视名称、书籍名称、简介
class TextInputPanel extends StatefulWidget {
final String title;
final String initialValue;
final String hint;
final TextInputType keyboardType;
final int maxLines;
const TextInputPanel({
super.key,
@@ -13,6 +14,7 @@ class TextInputPanel extends StatefulWidget {
this.initialValue = '',
this.hint = '',
this.keyboardType = TextInputType.text,
this.maxLines = 1,
});
static Future<String?> show({
@@ -21,6 +23,7 @@ class TextInputPanel extends StatefulWidget {
String initialValue = '',
String hint = '',
TextInputType keyboardType = TextInputType.text,
int maxLines = 1,
}) {
return showGeneralDialog<String>(
context: context,
@@ -40,6 +43,7 @@ class TextInputPanel extends StatefulWidget {
initialValue: initialValue,
hint: hint,
keyboardType: keyboardType,
maxLines: maxLines,
),
),
);
@@ -107,7 +111,8 @@ class _TextInputPanelState extends State<TextInputPanel> {
child: TextField(
controller: _controller,
autofocus: true,
keyboardType: widget.keyboardType,
keyboardType: widget.maxLines > 1 ? TextInputType.multiline : widget.keyboardType,
maxLines: widget.maxLines,
style: TextStyle(fontSize: 15, color: colors.onSurface),
cursorColor: colors.primary,
decoration: InputDecoration(