Skip to content

Commit 0ba987f

Browse files
committed
fix: Drag-and-drop-homepage-style
1 parent 21009c9 commit 0ba987f

2 files changed

Lines changed: 99 additions & 112 deletions

File tree

lib/app/home/page.dart

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,14 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
452452
children.add(_buildForecast());
453453
if (!_isLoading && _weather != null) children.add(_buildWindCard());
454454
break;
455+
case HomeDisplaySection.wind:
456+
if (!_isLoading && _weather != null) children.add(_buildWindCard());
457+
break;
455458
case HomeDisplaySection.history:
456459
children.add(_buildHistoryTimeline());
457460
break;
458461
}
459462
}
460-
461463
if (homeSections.isEmpty && GlobalProviders.location.code != null) {
462464
children.add(
463465
Padding(
@@ -477,42 +479,10 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
477479
],
478480
),
479481
),
480-
// 實時警報
481-
if (!_isLoading) ..._buildRealtimeInfo(),
482-
// 其他區塊
483-
if (homeSections.isNotEmpty) ...[
484-
if (homeSections.contains(HomeDisplaySection.radar)) _buildRadarMap(),
485-
if (homeSections.contains(HomeDisplaySection.forecast))
486-
_buildForecast(),
487-
if (!_isLoading &&
488-
homeSections.contains(HomeDisplaySection.wind) &&
489-
_weather != null)
490-
_buildWindCard(),
491-
_buildCommunityCards(),
492-
if (homeSections.contains(HomeDisplaySection.history))
493-
_buildHistoryTimeline(),
494-
] else if (GlobalProviders.location.code != null)
495-
Padding(
496-
padding: const EdgeInsets.all(16),
497-
child: Column(
498-
children: [
499-
Text(
500-
'您還沒有啟用首頁區塊,請到設定選擇要顯示的內容。'.i18n,
501-
textAlign: TextAlign.center,
502-
style: TextStyle(color: Colors.white.withValues(alpha: 0.8)),
503-
),
504-
const SizedBox(height: 12),
505-
FilledButton(
506-
onPressed: () => SettingsLayoutRoute().push(context),
507-
child: Text('前往設定'.i18n),
508-
),
509-
],
510-
),
511-
),
512-
// 底部安全區域
513-
SizedBox(height: MediaQuery.of(context).padding.bottom + 16),
514482
);
515483
};
484+
children.add(_buildCommunityCards());
485+
children.add(SizedBox(height: MediaQuery.of(context).padding.bottom + 16));
516486

517487
return Column(children: children);
518488
}

lib/app/settings/layout/page.dart

Lines changed: 94 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class SettingsLayoutPage extends StatelessWidget {
2929
const SizedBox(height: 16),
3030
if (enabledSections.isNotEmpty) ...[
3131
Padding(
32-
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
32+
padding: const EdgeInsets.symmetric(
33+
horizontal: 16,
34+
vertical: 8,
35+
),
3336
child: Text(
3437
'顯示中'.i18n,
3538
style: context.texts.labelLarge?.copyWith(
@@ -67,95 +70,100 @@ class SettingsLayoutPage extends StatelessWidget {
6770
],
6871
if (disabledSections.isNotEmpty) ...[
6972
Padding(
70-
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
73+
padding: const EdgeInsets.symmetric(
74+
horizontal: 16,
75+
vertical: 8,
76+
),
7177
child: Text(
7278
'已隱藏'.i18n,
7379
style: context.texts.labelLarge?.copyWith(
7480
color: context.colors.onSurfaceVariant,
7581
),
7682
),
7783
),
78-
...disabledSections.map((section) {
79-
final details = _getSectionDetails(section);
80-
return _buildSectionCard(
81-
context,
82-
key: ValueKey(section),
83-
icon: details.icon,
84-
iconColor: details.color,
85-
title: details.title,
86-
subtitle: details.subtitle,
87-
value: false,
88-
onChanged: (v) => model.toggleSection(section, v),
89-
isReorderable: false,
90-
);
91-
},
92-
),
93-
Selector<SettingsUserInterfaceModel, bool>(
94-
selector: (context, model) => model.isEnabled(.forecast),
95-
builder: (context, isEnabled, child) {
96-
return SectionListTile(
97-
leading: ContainedIcon(
98-
Symbols.radar_rounded,
99-
color: Colors.orangeAccent,
100-
),
101-
title: Text('天氣預報'.i18n),
102-
subtitle: Text('顯示未來 24 小時的天氣預報'.i18n),
103-
trailing: Switch(
104-
value: isEnabled,
105-
onChanged: (value) {
106-
context.userInterface.toggleSection(.forecast, value);
107-
},
108-
),
109-
);
110-
},
111-
),
112-
Selector<SettingsUserInterfaceModel, bool>(
113-
selector: (context, model) => model.isEnabled(.wind),
114-
builder: (context, isEnabled, child) {
115-
return SectionListTile(
116-
leading: ContainedIcon(
117-
Symbols.wind_power_rounded,
118-
color: Colors.orangeAccent,
119-
),
120-
title: Text('風向'.i18n),
121-
subtitle: Text('顯示風向與風力級數'.i18n),
122-
trailing: Switch(
123-
value: isEnabled,
124-
onChanged: (value) {
125-
context.userInterface.toggleSection(.wind, value);
126-
},
127-
),
128-
);
129-
},
130-
),
131-
Selector<SettingsUserInterfaceModel, bool>(
132-
selector: (context, model) => model.isEnabled(.history),
133-
builder: (context, isEnabled, child) {
134-
return SectionListTile(
135-
isLast: true,
136-
leading: ContainedIcon(
137-
Symbols.history_rounded,
138-
color: Colors.greenAccent,
139-
),
140-
title: Text('歷史事件'.i18n),
141-
subtitle: Text('顯示地震與災害歷史紀錄'.i18n),
142-
trailing: Switch(
143-
value: isEnabled,
144-
onChanged: (value) {
145-
context.userInterface.toggleSection(.history, value);
146-
},
147-
),
148-
);
149-
},
150-
),
84+
...disabledSections.map(
85+
(section) {
86+
final details = _getSectionDetails(section);
87+
return _buildSectionCard(
88+
context,
89+
key: ValueKey(section),
90+
icon: details.icon,
91+
iconColor: details.color,
92+
title: details.title,
93+
subtitle: details.subtitle,
94+
value: false,
95+
onChanged: (v) => model.toggleSection(section, v),
96+
isReorderable: false,
97+
);
98+
},
99+
),
100+
Selector<SettingsUserInterfaceModel, bool>(
101+
selector: (context, model) => model.isEnabled(.forecast),
102+
builder: (context, isEnabled, child) {
103+
return SectionListTile(
104+
leading: ContainedIcon(
105+
Symbols.radar_rounded,
106+
color: Colors.orangeAccent,
107+
),
108+
title: Text('天氣預報'.i18n),
109+
subtitle: Text('顯示未來 24 小時的天氣預報'.i18n),
110+
trailing: Switch(
111+
value: isEnabled,
112+
onChanged: (value) {
113+
context.userInterface.toggleSection(.forecast, value);
114+
},
115+
),
116+
);
117+
},
118+
),
119+
Selector<SettingsUserInterfaceModel, bool>(
120+
selector: (context, model) => model.isEnabled(.wind),
121+
builder: (context, isEnabled, child) {
122+
return SectionListTile(
123+
leading: ContainedIcon(
124+
Symbols.wind_power_rounded,
125+
color: Colors.orangeAccent,
126+
),
127+
title: Text('風向'.i18n),
128+
subtitle: Text('顯示風向與風力級數'.i18n),
129+
trailing: Switch(
130+
value: isEnabled,
131+
onChanged: (value) {
132+
context.userInterface.toggleSection(.wind, value);
133+
},
134+
),
135+
);
136+
},
137+
),
138+
Selector<SettingsUserInterfaceModel, bool>(
139+
selector: (context, model) => model.isEnabled(.history),
140+
builder: (context, isEnabled, child) {
141+
return SectionListTile(
142+
isLast: true,
143+
leading: ContainedIcon(
144+
Symbols.history_rounded,
145+
color: Colors.greenAccent,
146+
),
147+
title: Text('歷史事件'.i18n),
148+
subtitle: Text('顯示地震與災害歷史紀錄'.i18n),
149+
trailing: Switch(
150+
value: isEnabled,
151+
onChanged: (value) {
152+
context.userInterface.toggleSection(.history, value);
153+
},
154+
),
155+
);
156+
},
157+
),
158+
],
151159
],
152160
);
153161
},
154162
);
155163
}
156164

157165
({IconData icon, Color color, String title, String subtitle})
158-
_getSectionDetails(HomeDisplaySection section) {
166+
_getSectionDetails(HomeDisplaySection section) {
159167
switch (section) {
160168
case HomeDisplaySection.radar:
161169
return (
@@ -178,6 +186,13 @@ class SettingsLayoutPage extends StatelessWidget {
178186
title: '歷史事件'.i18n,
179187
subtitle: '顯示地震與災害歷史紀錄'.i18n,
180188
);
189+
case HomeDisplaySection.wind:
190+
return (
191+
icon: Symbols.wind_power_rounded,
192+
color: Colors.purple,
193+
title: '風向'.i18n,
194+
subtitle: '顯示風向與風力級數'.i18n,
195+
);
181196
}
182197
}
183198

@@ -258,7 +273,9 @@ class SettingsLayoutPage extends StatelessWidget {
258273
if (isReorderable) ...[
259274
Icon(
260275
Symbols.drag_handle_rounded,
261-
color: context.colors.onSurfaceVariant.withValues(alpha: 0.5),
276+
color: context.colors.onSurfaceVariant.withValues(
277+
alpha: 0.5,
278+
),
262279
),
263280
const SizedBox(width: 12),
264281
],

0 commit comments

Comments
 (0)