@@ -16,15 +16,37 @@ class _DetectedModel {
1616 const _DetectedModel (this .id, [this .contextWindow = 0 ]);
1717}
1818
19- class ModelCardsPage extends ConsumerWidget {
19+ class ModelCardsPage extends ConsumerStatefulWidget {
2020 const ModelCardsPage ({super .key});
2121
2222 @override
23- Widget build (BuildContext context, WidgetRef ref) {
23+ ConsumerState <ModelCardsPage > createState () => _ModelCardsPageState ();
24+ }
25+
26+ class _ModelCardsPageState extends ConsumerState <ModelCardsPage > {
27+ /// 是否处于排序模式(拖拽可用)
28+ bool _reorderMode = false ;
29+
30+ @override
31+ Widget build (BuildContext context) {
2432 final cardsAsync = ref.watch (modelCardsProvider);
2533
2634 return Scaffold (
27- appBar: AppBar (title: Text (context.s.modelsTitle)),
35+ appBar: AppBar (
36+ title: Text (context.s.modelsTitle),
37+ actions: [
38+ // 排序模式切换
39+ if (cardsAsync.valueOrNull != null &&
40+ cardsAsync.valueOrNull! .length > 1 )
41+ IconButton (
42+ icon: Icon (
43+ _reorderMode ? Icons .done : Icons .swap_vert,
44+ ),
45+ tooltip: _reorderMode ? '完成排序' : '拖拽排序' ,
46+ onPressed: () => setState (() => _reorderMode = ! _reorderMode),
47+ ),
48+ ],
49+ ),
2850 body: cardsAsync.when (
2951 loading: () => const Center (child: CircularProgressIndicator ()),
3052 error: (err, stack) =>
@@ -62,25 +84,47 @@ class ModelCardsPage extends ConsumerWidget {
6284 child: Column (
6385 crossAxisAlignment: CrossAxisAlignment .start,
6486 children: [
65- Padding (
66- padding: const EdgeInsets .only (bottom: 12 ),
67- child: Text (
68- context.s.modelsReorderHint,
69- style: Theme .of (context).textTheme.bodySmall? .copyWith (
70- color: Theme .of (context).colorScheme.onSurfaceVariant,
87+ if (_reorderMode)
88+ Padding (
89+ padding: const EdgeInsets .only (bottom: 12 ),
90+ child: Text (
91+ context.s.modelsReorderHint,
92+ style: Theme .of (context).textTheme.bodySmall? .copyWith (
93+ color: Theme .of (context).colorScheme.onSurfaceVariant,
94+ ),
7195 ),
7296 ),
73- ),
74- ReorderableCardGrid <ModelCard >(
75- items: cards,
76- keyOf: (c) => c.id,
77- onReorder: (reordered) =>
78- ref.read (modelCardsProvider.notifier).reorder (reordered),
79- itemBuilder: (context, card) => _ModelCardTile (card: card),
80- trailing: _AddModelCard (
81- onTap: () => _showAddDialog (context, ref),
97+ // 排序模式:带拖拽的重排网格
98+ // 普通模式:轻量 Wrap,点击即切换默认,无拖拽开销
99+ if (_reorderMode)
100+ ReorderableCardGrid <ModelCard >(
101+ items: cards,
102+ keyOf: (c) => c.id,
103+ onReorder: (reordered) =>
104+ ref.read (modelCardsProvider.notifier).reorder (reordered),
105+ itemBuilder: (context, card) => _ModelCardTile (card: card),
106+ trailing: _AddModelCard (
107+ onTap: () => _showAddDialog (context, ref),
108+ ),
109+ )
110+ else
111+ Wrap (
112+ spacing: 12 ,
113+ runSpacing: 12 ,
114+ children: [
115+ for (final card in cards)
116+ SizedBox (
117+ width: 280 ,
118+ child: _ModelCardTile (card: card),
119+ ),
120+ SizedBox (
121+ width: 280 ,
122+ child: _AddModelCard (
123+ onTap: () => _showAddDialog (context, ref),
124+ ),
125+ ),
126+ ],
82127 ),
83- ),
84128 ],
85129 ),
86130 );
0 commit comments