generated from dellevin/template
代码优化,功能新增
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 带动画的星级评分组件 — 星星依次亮起 + 数字滚动
|
||||
class AnimatedStarRating extends StatefulWidget {
|
||||
/// 静态星级评分组件
|
||||
class AnimatedStarRating extends StatelessWidget {
|
||||
final double rating;
|
||||
final double starSize;
|
||||
final Color color;
|
||||
@@ -15,48 +15,10 @@ class AnimatedStarRating extends StatefulWidget {
|
||||
this.showNumber = false,
|
||||
});
|
||||
|
||||
@override
|
||||
State<AnimatedStarRating> createState() => _AnimatedStarRatingState();
|
||||
}
|
||||
|
||||
class _AnimatedStarRatingState extends State<AnimatedStarRating>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _controller;
|
||||
late List<Animation<double>> _animations;
|
||||
late Animation<double> _numberAnim;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 600),
|
||||
);
|
||||
_animations = List.generate(5, (i) {
|
||||
return CurvedAnimation(
|
||||
parent: _controller,
|
||||
curve: Interval(i * 0.12, (i * 0.12) + 0.35, curve: Curves.easeOutBack),
|
||||
);
|
||||
});
|
||||
_numberAnim = Tween<double>(begin: 0, end: widget.rating).animate(
|
||||
CurvedAnimation(
|
||||
parent: _controller,
|
||||
curve: const Interval(0.1, 0.8, curve: Curves.easeOut),
|
||||
),
|
||||
);
|
||||
_controller.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final starValue = widget.rating / 2;
|
||||
final starValue = rating / 2;
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@@ -70,25 +32,17 @@ class _AnimatedStarRatingState extends State<AnimatedStarRating>
|
||||
} else {
|
||||
iconData = Icons.star_border;
|
||||
}
|
||||
return ScaleTransition(
|
||||
scale: _animations[index],
|
||||
child: Icon(iconData, size: widget.starSize, color: widget.color),
|
||||
);
|
||||
return Icon(iconData, size: starSize, color: color);
|
||||
}),
|
||||
if (widget.showNumber) ...[
|
||||
if (showNumber) ...[
|
||||
const SizedBox(width: 4),
|
||||
AnimatedBuilder(
|
||||
animation: _numberAnim,
|
||||
builder: (context, child) {
|
||||
return Text(
|
||||
_numberAnim.value.toStringAsFixed(1),
|
||||
style: TextStyle(
|
||||
fontSize: widget.starSize,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: colors.onSurface.withValues(alpha: 0.6),
|
||||
),
|
||||
);
|
||||
},
|
||||
Text(
|
||||
rating.toStringAsFixed(1),
|
||||
style: TextStyle(
|
||||
fontSize: starSize,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: colors.onSurface.withValues(alpha: 0.6),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
@@ -5,6 +5,8 @@ import 'package:package_info_plus/package_info_plus.dart';
|
||||
import '../providers/app_provider.dart';
|
||||
import '../utils/user_prefs.dart';
|
||||
import '../pages/stroll_page.dart';
|
||||
import '../pages/media_calendar_page.dart';
|
||||
import '../pages/person_list_page.dart';
|
||||
import '../pages/markdown_reader/md_reader_tab_page.dart';
|
||||
import '../pages/tag_management_page.dart';
|
||||
import '../pages/reader/bookshelf_page.dart';
|
||||
@@ -173,6 +175,16 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (_) => const StrollPage()));
|
||||
}, topRounded: true),
|
||||
Divider(height: 1, indent: 52, endIndent: 20, color: colors.outlineVariant),
|
||||
_buildToolItem(Icons.calendar_month_outlined, '书影日历', () {
|
||||
Navigator.pop(context);
|
||||
Navigator.push(context, MaterialPageRoute(builder: (_) => const MediaCalendarPage()));
|
||||
}),
|
||||
Divider(height: 1, indent: 52, endIndent: 20, color: colors.outlineVariant),
|
||||
_buildToolItem(Icons.people_outline, '角色信息', () {
|
||||
Navigator.pop(context);
|
||||
Navigator.push(context, MaterialPageRoute(builder: (_) => const PersonListPage()));
|
||||
}),
|
||||
Divider(height: 1, indent: 52, endIndent: 20, color: colors.outlineVariant),
|
||||
_buildToolItem(Icons.label_outline, '标签管理', () {
|
||||
Navigator.pop(context);
|
||||
Navigator.push(context, MaterialPageRoute(builder: (_) => const TagManagementPage()));
|
||||
@@ -252,8 +264,8 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
|
||||
const totalWeeks = 20;
|
||||
const weekDays = 7;
|
||||
const cellSize = 13.0;
|
||||
const cellGap = 3.0;
|
||||
const cellSize = 10.0;
|
||||
const cellGap = 1.5;
|
||||
|
||||
final cells = List.generate(weekDays, (_) => List.generate(totalWeeks, (_) => 0));
|
||||
for (int week = 0; week < totalWeeks; week++) {
|
||||
@@ -289,12 +301,10 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 16,
|
||||
child: Row(
|
||||
@@ -320,7 +330,6 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
|
||||
@@ -1,18 +1,55 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 类型/标签选择全屏页(影视类型、书籍类型通用)
|
||||
/// 类型/标签选择右侧弹窗(影视类型、导演、编剧、主演、书籍类型通用)
|
||||
class GenreSelectorPage extends StatefulWidget {
|
||||
final String title;
|
||||
final List<String> existingTags;
|
||||
final List<String>? existingTags;
|
||||
final Future<List<String>>? existingTagsFuture;
|
||||
final List<String> initialSelected;
|
||||
final String hint;
|
||||
const GenreSelectorPage({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.existingTags,
|
||||
this.existingTags,
|
||||
this.existingTagsFuture,
|
||||
required this.initialSelected,
|
||||
this.hint = '',
|
||||
});
|
||||
}) : assert(existingTags != null || existingTagsFuture != null, 'existingTags 和 existingTagsFuture 至少提供一个');
|
||||
|
||||
/// 显示右侧弹窗
|
||||
static Future<List<String>?> show({
|
||||
required BuildContext context,
|
||||
required String title,
|
||||
List<String>? existingTags,
|
||||
Future<List<String>>? existingTagsFuture,
|
||||
required List<String> initialSelected,
|
||||
String hint = '',
|
||||
}) {
|
||||
return showGeneralDialog<List<String>>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
barrierLabel: 'selector-panel',
|
||||
barrierColor: Colors.black.withValues(alpha: 0.3),
|
||||
transitionDuration: const Duration(milliseconds: 250),
|
||||
pageBuilder: (_, __, ___) => const SizedBox.shrink(),
|
||||
transitionBuilder: (ctx, anim, secAnim, child) {
|
||||
return SlideTransition(
|
||||
position: Tween(begin: const Offset(1, 0), end: Offset.zero)
|
||||
.animate(CurvedAnimation(parent: anim, curve: Curves.easeOut)),
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: GenreSelectorPage(
|
||||
title: title,
|
||||
existingTags: existingTags,
|
||||
existingTagsFuture: existingTagsFuture,
|
||||
initialSelected: initialSelected,
|
||||
hint: hint,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<GenreSelectorPage> createState() => _GenreSelectorPageState();
|
||||
@@ -21,12 +58,24 @@ class GenreSelectorPage extends StatefulWidget {
|
||||
class _GenreSelectorPageState extends State<GenreSelectorPage> {
|
||||
late List<String> _selected;
|
||||
final _controller = TextEditingController();
|
||||
String _newTag = '';
|
||||
String _query = '';
|
||||
List<String>? _loadedTags;
|
||||
bool _loading = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selected = List<String>.from(widget.initialSelected);
|
||||
_loadTags();
|
||||
}
|
||||
|
||||
Future<void> _loadTags() async {
|
||||
if (widget.existingTags != null) {
|
||||
_loadedTags = widget.existingTags;
|
||||
} else {
|
||||
_loadedTags = await widget.existingTagsFuture;
|
||||
}
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -46,11 +95,11 @@ class _GenreSelectorPageState extends State<GenreSelectorPage> {
|
||||
}
|
||||
|
||||
void _addCustom() {
|
||||
final tag = _newTag.trim();
|
||||
final tag = _query.trim();
|
||||
if (tag.isNotEmpty && !_selected.contains(tag)) {
|
||||
setState(() {
|
||||
_selected.add(tag);
|
||||
_newTag = '';
|
||||
_query = '';
|
||||
_controller.clear();
|
||||
});
|
||||
}
|
||||
@@ -59,118 +108,163 @@ class _GenreSelectorPageState extends State<GenreSelectorPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final available = widget.existingTags.where((t) => !_selected.contains(t)).toList();
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final allTags = _loadedTags ?? [];
|
||||
final query = _query.toLowerCase();
|
||||
final available = allTags
|
||||
.where((t) => !_selected.contains(t))
|
||||
.where((t) => query.isEmpty || t.toLowerCase().contains(query))
|
||||
.toList();
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: colors.surface,
|
||||
appBar: AppBar(
|
||||
title: Text(widget.title),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, _selected),
|
||||
child: Text('完成', style: TextStyle(
|
||||
fontSize: 15, fontWeight: FontWeight.w600, color: colors.primary,
|
||||
)),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 40),
|
||||
return Material(
|
||||
color: colors.surface,
|
||||
borderRadius: const BorderRadius.horizontal(left: Radius.circular(16)),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: SizedBox(
|
||||
width: screenWidth * 0.75,
|
||||
height: double.infinity,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 已选择
|
||||
if (_selected.isNotEmpty) ...[
|
||||
Text('已选择', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: colors.onSurface.withValues(alpha: 0.5))),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8, runSpacing: 8,
|
||||
children: _selected.map((tag) {
|
||||
final displayTag = tag.length > 8 ? '${tag.substring(0, 8)}...' : tag;
|
||||
return GestureDetector(
|
||||
onTap: () => _toggle(tag),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.primary, borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(displayTag, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: colors.onPrimary)),
|
||||
const SizedBox(width: 6),
|
||||
Icon(Icons.close, size: 14, color: colors.onPrimary.withValues(alpha: 0.7)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
// Header
|
||||
Container(
|
||||
padding: EdgeInsets.fromLTRB(16, MediaQuery.of(context).padding.top + 12, 8, 12),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: colors.outlineVariant, width: 0.5)),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
// 自定义输入
|
||||
Text('自定义添加', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: colors.onSurface.withValues(alpha: 0.5))),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
style: TextStyle(fontSize: 14, color: colors.onSurface),
|
||||
decoration: InputDecoration(
|
||||
hintText: widget.hint.isNotEmpty ? widget.hint : '输入自定义类型',
|
||||
hintStyle: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.3)),
|
||||
filled: true, fillColor: colors.surfaceContainerHighest,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide.none),
|
||||
),
|
||||
onChanged: (v) => setState(() => _newTag = v),
|
||||
onSubmitted: (_) => _addCustom(),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(widget.title, style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
const Spacer(),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, _selected),
|
||||
child: Text('完成', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: colors.primary)),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
GestureDetector(
|
||||
onTap: _addCustom,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: _newTag.trim().isNotEmpty ? colors.primary : colors.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(Icons.add, size: 20,
|
||||
color: _newTag.trim().isNotEmpty ? colors.onPrimary : colors.onSurface.withValues(alpha: 0.3)),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
// 已有类型
|
||||
if (available.isNotEmpty) ...[
|
||||
const SizedBox(height: 24),
|
||||
Text('已有类型', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: colors.onSurface.withValues(alpha: 0.5))),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8, runSpacing: 8,
|
||||
children: available.map((tag) {
|
||||
final displayTag = tag.length > 8 ? '${tag.substring(0, 8)}...' : tag;
|
||||
return GestureDetector(
|
||||
onTap: () => _toggle(tag),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHighest, borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.add, size: 14, color: colors.onSurface.withValues(alpha: 0.4)),
|
||||
const SizedBox(width: 4),
|
||||
Text(displayTag, style: TextStyle(fontSize: 13, color: colors.onSurface.withValues(alpha: 0.7))),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
|
||||
// 已选择(一行一个,最新在上)
|
||||
if (_selected.isNotEmpty) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text('已选择', style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.4))),
|
||||
),
|
||||
),
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.25),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: colors.outlineVariant, width: 0.5)),
|
||||
),
|
||||
child: ListView.builder(
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: _selected.length,
|
||||
itemBuilder: (_, i) {
|
||||
final tag = _selected[_selected.length - 1 - i];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 6),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: colors.primary.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: ListTile(
|
||||
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)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
// 搜索/输入框
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
style: TextStyle(fontSize: 14, color: colors.onSurface),
|
||||
cursorColor: colors.primary,
|
||||
decoration: InputDecoration(
|
||||
hintText: widget.hint.isNotEmpty ? '搜索或${widget.hint}' : '搜索或输入',
|
||||
hintStyle: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.3)),
|
||||
filled: true,
|
||||
fillColor: colors.surfaceContainerHigh,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide.none),
|
||||
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide.none),
|
||||
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: colors.primary, width: 1)),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(Icons.add, size: 20,
|
||||
color: _query.trim().isNotEmpty ? colors.primary : colors.onSurface.withValues(alpha: 0.25)),
|
||||
onPressed: _addCustom,
|
||||
),
|
||||
),
|
||||
onChanged: (v) => setState(() => _query = v),
|
||||
onSubmitted: (_) => _addCustom(),
|
||||
),
|
||||
),
|
||||
|
||||
// 已有类型/搜索结果
|
||||
if (allTags.isNotEmpty) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
_loading ? '加载中...' : (query.isEmpty ? '已有类型' : '匹配结果'),
|
||||
style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.4)),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: _loading
|
||||
? Center(child: CircularProgressIndicator(strokeWidth: 2, color: colors.primary))
|
||||
: available.isEmpty
|
||||
? Center(child: Text(
|
||||
query.isEmpty ? '暂无已有选项' : '无匹配结果,回车添加',
|
||||
style: TextStyle(fontSize: 13, color: colors.onSurface.withValues(alpha: 0.3)),
|
||||
))
|
||||
: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 24),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: available.map((tag) {
|
||||
return GestureDetector(
|
||||
onTap: () => _toggle(tag),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: colors.outline, width: 0.5),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.add, size: 14, color: colors.onSurface.withValues(alpha: 0.4)),
|
||||
const SizedBox(width: 4),
|
||||
Text(tag, style: TextStyle(fontSize: 13, color: colors.onSurface.withValues(alpha: 0.7))),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../providers/app_provider.dart';
|
||||
import '../models/data_models.dart';
|
||||
import '../utils/toast_util.dart';
|
||||
import 'fade_in_local_image.dart';
|
||||
|
||||
/// 笔记列表项组件 - 极简主义设计
|
||||
@@ -29,13 +27,12 @@ class _NoteListItemContent extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
onTap: () async {
|
||||
final provider = context.read<AppProvider>();
|
||||
Navigator.pushNamed(context, '/note-detail', arguments: note).then((_) async {
|
||||
await provider.loadNotes();
|
||||
});
|
||||
await Navigator.pushNamed(context, '/note-detail', arguments: note);
|
||||
await provider.loadNotes();
|
||||
},
|
||||
onLongPress: () => _showDeleteDialog(context),
|
||||
onLongPress: () => _showActions(context),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
padding: const EdgeInsets.fromLTRB(12, 10, 12, 10),
|
||||
@@ -48,6 +45,7 @@ class _NoteListItemContent extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// 日期行
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
@@ -74,6 +72,10 @@ class _NoteListItemContent extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (note.isPinned) ...[
|
||||
const SizedBox(width: 6),
|
||||
Icon(Icons.push_pin, size: 12, color: colors.primary),
|
||||
],
|
||||
],
|
||||
),
|
||||
|
||||
@@ -106,6 +108,44 @@ class _NoteListItemContent extends StatelessWidget {
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
|
||||
// 图片缩略图(最多3张,超出显示 +N)
|
||||
if (note.images.isNotEmpty) ...[
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
for (int i = 0; i < note.images.length.clamp(0, 3); i++) ...[
|
||||
if (i > 0) const SizedBox(width: 6),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Stack(
|
||||
children: [
|
||||
FadeInLocalImage(
|
||||
path: note.images[i],
|
||||
width: 56, height: 56,
|
||||
fit: BoxFit.cover,
|
||||
errorWidget: Container(width: 56, height: 56, color: colors.surfaceContainerHighest),
|
||||
),
|
||||
// 第3张且有更多时显示 +N
|
||||
if (i == 2 && note.images.length > 3)
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.45),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text('+${note.images.length - 3}',
|
||||
style: const TextStyle(fontSize: 13, color: Colors.white, fontWeight: FontWeight.w600)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
if (note.tags.isNotEmpty) ...[
|
||||
const SizedBox(height: 6),
|
||||
Wrap(
|
||||
@@ -130,56 +170,80 @@ class _NoteListItemContent extends StatelessWidget {
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
|
||||
if (note.images.isNotEmpty) ...[
|
||||
const SizedBox(height: 8),
|
||||
_buildImagePreviewRow(colors),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildImagePreviewRow(ColorScheme colors) {
|
||||
final images = note.images;
|
||||
final count = images.length.clamp(0, 3);
|
||||
return Row(
|
||||
children: [
|
||||
for (int i = 0; i < count; i++)
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
margin: const EdgeInsets.only(right: 6),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
border: Border.all(color: colors.outlineVariant, width: 0.5),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: FadeInLocalImage(
|
||||
path: images[i],
|
||||
fit: BoxFit.cover,
|
||||
errorWidget: Container(
|
||||
color: colors.surfaceContainerHighest,
|
||||
),
|
||||
),
|
||||
void _showActions(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: colors.surface,
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(16))),
|
||||
builder: (ctx) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Container(width: 36, height: 4, decoration: BoxDecoration(color: colors.onSurface.withValues(alpha: 0.15), borderRadius: BorderRadius.circular(2))),
|
||||
const SizedBox(height: 16),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Container(width: 36, height: 36, decoration: BoxDecoration(color: colors.surfaceContainerHighest, borderRadius: BorderRadius.circular(10)),
|
||||
child: Icon(note.isPinned ? Icons.push_pin_outlined : Icons.push_pin, size: 20, color: colors.onSurface.withValues(alpha: 0.6))),
|
||||
title: Text(note.isPinned ? '取消置顶' : '置顶', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: colors.onSurface)),
|
||||
subtitle: Text(note.isPinned ? '取消置顶后按时间排序' : '置顶后始终显示在最前', style: TextStyle(fontSize: 11, color: colors.onSurface.withValues(alpha: 0.4))),
|
||||
trailing: Icon(Icons.chevron_right, color: colors.onSurface.withValues(alpha: 0.25)),
|
||||
onTap: () {
|
||||
Navigator.pop(ctx);
|
||||
context.read<AppProvider>().toggleNotePin(note.id, !note.isPinned);
|
||||
},
|
||||
),
|
||||
if (images.length > 3)
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'+${images.length - 3}',
|
||||
style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.4), fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
Divider(height: 0.5, color: colors.outlineVariant),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Container(width: 36, height: 36, decoration: BoxDecoration(color: colors.surfaceContainerHighest, borderRadius: BorderRadius.circular(10)),
|
||||
child: Icon(Icons.delete_outline, size: 20, color: colors.error)),
|
||||
title: Text('删除', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: colors.error)),
|
||||
subtitle: Text('删除后可在回收站恢复', style: TextStyle(fontSize: 11, color: colors.onSurface.withValues(alpha: 0.4))),
|
||||
trailing: Icon(Icons.chevron_right, color: colors.onSurface.withValues(alpha: 0.25)),
|
||||
onTap: () {
|
||||
Navigator.pop(ctx);
|
||||
_showDeleteConfirm(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showDeleteConfirm(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
backgroundColor: colors.surface, elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
title: Text('确认删除', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
content: Text('确定要删除这条笔记吗?删除后可在回收站恢复。',
|
||||
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6), height: 1.5)),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx),
|
||||
child: Text('取消', style: TextStyle(color: colors.onSurface.withValues(alpha: 0.6)))),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
await context.read<AppProvider>().removeNote(note.id);
|
||||
Navigator.pop(ctx);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(backgroundColor: colors.error, foregroundColor: colors.onError, elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8)),
|
||||
child: const Text('删除'),
|
||||
),
|
||||
],
|
||||
actionsPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -199,62 +263,6 @@ class _NoteListItemContent extends StatelessWidget {
|
||||
String _collapseBlankLines(String text) {
|
||||
return text.replaceAll(RegExp(r'\n\s*\n+'), '\n');
|
||||
}
|
||||
|
||||
void _showDeleteDialog(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
backgroundColor: colors.surface,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
title: Text(
|
||||
'确认删除',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: colors.onSurface,
|
||||
),
|
||||
),
|
||||
content: Text(
|
||||
'确定要删除这条笔记吗?删除后可在回收站恢复。',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: colors.onSurface.withValues(alpha: 0.6),
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: colors.onSurface.withValues(alpha: 0.6),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
await context.read<AppProvider>().removeNote(note.id);
|
||||
Navigator.pop(context);
|
||||
ToastUtil.show(context, '已删除');
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: colors.error,
|
||||
foregroundColor: colors.onError,
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
),
|
||||
child: const Text('删除'),
|
||||
),
|
||||
],
|
||||
actionsPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
@@ -262,7 +270,6 @@ String _formatDate(DateTime date) {
|
||||
final difference = now.difference(date);
|
||||
|
||||
if (difference.isNegative) {
|
||||
// 服务端时间比本地快(时钟偏差),显示绝对日期
|
||||
return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}';
|
||||
}
|
||||
if (difference.inDays == 0) {
|
||||
|
||||
237
lib/widgets/tag_side_panel.dart
Normal file
237
lib/widgets/tag_side_panel.dart
Normal file
@@ -0,0 +1,237 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 标签侧边面板 - 从右侧滑入,用于选择和新建标签
|
||||
class TagSidePanel extends StatefulWidget {
|
||||
final List<String> selectedTags;
|
||||
final List<String> allAvailableTags;
|
||||
final ValueChanged<List<String>> onTagsChanged;
|
||||
|
||||
const TagSidePanel({
|
||||
super.key,
|
||||
required this.selectedTags,
|
||||
required this.allAvailableTags,
|
||||
required this.onTagsChanged,
|
||||
});
|
||||
|
||||
static Future<void> show({
|
||||
required BuildContext context,
|
||||
required List<String> selectedTags,
|
||||
required List<String> allAvailableTags,
|
||||
required ValueChanged<List<String>> onTagsChanged,
|
||||
}) {
|
||||
return showGeneralDialog(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
barrierLabel: 'tag-panel',
|
||||
barrierColor: Colors.black.withValues(alpha: 0.3),
|
||||
transitionDuration: const Duration(milliseconds: 250),
|
||||
pageBuilder: (_, __, ___) => const SizedBox.shrink(),
|
||||
transitionBuilder: (ctx, anim, secAnim, child) {
|
||||
return SlideTransition(
|
||||
position: Tween(begin: const Offset(1, 0), end: Offset.zero)
|
||||
.animate(CurvedAnimation(parent: anim, curve: Curves.easeOut)),
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: TagSidePanel(
|
||||
selectedTags: selectedTags,
|
||||
allAvailableTags: allAvailableTags,
|
||||
onTagsChanged: onTagsChanged,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<TagSidePanel> createState() => _TagSidePanelState();
|
||||
}
|
||||
|
||||
class _TagSidePanelState extends State<TagSidePanel> {
|
||||
late List<String> _selected;
|
||||
final _inputController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_selected = List.from(widget.selectedTags);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_inputController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _toggleTag(String tag) {
|
||||
setState(() {
|
||||
if (_selected.contains(tag)) {
|
||||
_selected.remove(tag);
|
||||
} else {
|
||||
_selected.add(tag);
|
||||
}
|
||||
});
|
||||
widget.onTagsChanged(_selected);
|
||||
}
|
||||
|
||||
void _addNewTag() {
|
||||
final tag = _inputController.text.trim();
|
||||
if (tag.isEmpty) return;
|
||||
if (!_selected.contains(tag)) {
|
||||
setState(() => _selected.add(tag));
|
||||
widget.onTagsChanged(_selected);
|
||||
}
|
||||
_inputController.clear();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
return Material(
|
||||
color: colors.surface,
|
||||
borderRadius: const BorderRadius.horizontal(left: Radius.circular(16)),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: SizedBox(
|
||||
width: screenWidth * 0.75,
|
||||
height: double.infinity,
|
||||
child: Column(
|
||||
children: [
|
||||
// Header
|
||||
Container(
|
||||
padding: EdgeInsets.fromLTRB(16, MediaQuery.of(context).padding.top + 12, 8, 12),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: colors.outlineVariant, width: 0.5)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text('标签', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
icon: Icon(Icons.close, size: 20, color: colors.onSurface.withValues(alpha: 0.6)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// 新建标签输入框
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
||||
child: TextField(
|
||||
controller: _inputController,
|
||||
style: TextStyle(fontSize: 14, color: colors.onSurface),
|
||||
cursorColor: colors.primary,
|
||||
decoration: InputDecoration(
|
||||
hintText: '输入新标签,回车添加',
|
||||
hintStyle: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.3)),
|
||||
filled: true,
|
||||
fillColor: colors.surfaceContainerHigh,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: colors.primary, width: 1),
|
||||
),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(Icons.add, size: 18, color: colors.primary),
|
||||
onPressed: _addNewTag,
|
||||
),
|
||||
),
|
||||
onSubmitted: (_) => _addNewTag(),
|
||||
),
|
||||
),
|
||||
|
||||
// 已选标签
|
||||
if (_selected.isNotEmpty) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 0),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text('已选标签', style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.4))),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: _selected.map((tag) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.primary,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: GestureDetector(
|
||||
onTap: () => _toggleTag(tag),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(tag, style: TextStyle(fontSize: 13, color: colors.onPrimary)),
|
||||
const SizedBox(width: 4),
|
||||
Icon(Icons.close, size: 14, color: colors.onPrimary),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
// 全部标签
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 0),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text('全部标签', style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.4))),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 24),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: widget.allAvailableTags.map((tag) {
|
||||
final isSelected = _selected.contains(tag);
|
||||
return GestureDetector(
|
||||
onTap: () => _toggleTag(tag),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? colors.primary.withValues(alpha: 0.15) : colors.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: isSelected ? colors.primary : colors.outline,
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
tag,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: isSelected ? colors.primary : colors.onSurface.withValues(alpha: 0.7),
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
138
lib/widgets/text_input_panel.dart
Normal file
138
lib/widgets/text_input_panel.dart
Normal file
@@ -0,0 +1,138 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 右侧滑入文本输入弹窗(单行编辑用,如影视名称、书籍名称)
|
||||
class TextInputPanel extends StatefulWidget {
|
||||
final String title;
|
||||
final String initialValue;
|
||||
final String hint;
|
||||
final TextInputType keyboardType;
|
||||
|
||||
const TextInputPanel({
|
||||
super.key,
|
||||
required this.title,
|
||||
this.initialValue = '',
|
||||
this.hint = '',
|
||||
this.keyboardType = TextInputType.text,
|
||||
});
|
||||
|
||||
static Future<String?> show({
|
||||
required BuildContext context,
|
||||
required String title,
|
||||
String initialValue = '',
|
||||
String hint = '',
|
||||
TextInputType keyboardType = TextInputType.text,
|
||||
}) {
|
||||
return showGeneralDialog<String>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
barrierLabel: 'text-input-panel',
|
||||
barrierColor: Colors.black.withValues(alpha: 0.3),
|
||||
transitionDuration: const Duration(milliseconds: 250),
|
||||
pageBuilder: (_, __, ___) => const SizedBox.shrink(),
|
||||
transitionBuilder: (ctx, anim, secAnim, child) {
|
||||
return SlideTransition(
|
||||
position: Tween(begin: const Offset(1, 0), end: Offset.zero)
|
||||
.animate(CurvedAnimation(parent: anim, curve: Curves.easeOut)),
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: TextInputPanel(
|
||||
title: title,
|
||||
initialValue: initialValue,
|
||||
hint: hint,
|
||||
keyboardType: keyboardType,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<TextInputPanel> createState() => _TextInputPanelState();
|
||||
}
|
||||
|
||||
class _TextInputPanelState extends State<TextInputPanel> {
|
||||
late final TextEditingController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = TextEditingController(text: widget.initialValue);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
final value = _controller.text.trim();
|
||||
Navigator.pop(context, value);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
return Material(
|
||||
color: colors.surface,
|
||||
borderRadius: const BorderRadius.horizontal(left: Radius.circular(16)),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: SizedBox(
|
||||
width: screenWidth * 0.75,
|
||||
height: double.infinity,
|
||||
child: Column(
|
||||
children: [
|
||||
// Header
|
||||
Container(
|
||||
padding: EdgeInsets.fromLTRB(16, MediaQuery.of(context).padding.top + 12, 8, 12),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: colors.outlineVariant, width: 0.5)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(widget.title, style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: colors.onSurface)),
|
||||
const Spacer(),
|
||||
TextButton(
|
||||
onPressed: _submit,
|
||||
child: Text('完成', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: colors.primary)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// 输入框
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
autofocus: true,
|
||||
keyboardType: widget.keyboardType,
|
||||
style: TextStyle(fontSize: 15, color: colors.onSurface),
|
||||
cursorColor: colors.primary,
|
||||
decoration: InputDecoration(
|
||||
hintText: widget.hint,
|
||||
hintStyle: TextStyle(fontSize: 15, color: colors.onSurface.withValues(alpha: 0.3)),
|
||||
filled: true,
|
||||
fillColor: colors.surfaceContainerHigh,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide.none),
|
||||
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide.none),
|
||||
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide(color: colors.primary, width: 1)),
|
||||
suffixIcon: _controller.text.isNotEmpty
|
||||
? IconButton(
|
||||
icon: Icon(Icons.clear, size: 18, color: colors.onSurface.withValues(alpha: 0.35)),
|
||||
onPressed: () => _controller.clear(),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
onChanged: (_) => setState(() {}),
|
||||
onSubmitted: (_) => _submit(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user