fix:UI对齐demo

This commit is contained in:
jingyun
2026-06-18 18:08:29 +08:00
parent f42ad566e0
commit 2d7523f901
14 changed files with 1613 additions and 355 deletions
@@ -4,6 +4,8 @@ import 'package:shadcn_ui/shadcn_ui.dart';
import '../../../common/domain/metal_type.dart';
import '../../../common/widgets/prototype_ui.dart';
import '../../profile/application/price_color_theme.dart';
import '../../profile/application/profile_settings_controller.dart';
import '../data/mock_market_repository.dart';
import '../data/market_models.dart';
@@ -21,6 +23,9 @@ class MarketKlinePage extends ConsumerWidget {
final quote = repo.quoteFor(metal);
final points = repo.chartFor(metal, period);
final cs = ShadTheme.of(context).colorScheme;
final palette = priceColorPalette(
ref.watch(profileSettingsControllerProvider).priceColorMode,
);
return Scaffold(
backgroundColor: const Color(0xFFFBFAF7),
@@ -74,7 +79,13 @@ class MarketKlinePage extends ConsumerWidget {
const SizedBox(width: 4),
const Padding(
padding: EdgeInsets.only(top: 8),
child: Text('元/克', style: TextStyle(fontSize: 12, color: Color(0xFF8A8780))),
child: Text(
'元/克',
style: TextStyle(
fontSize: 12,
color: Color(0xFF8A8780),
),
),
),
],
),
@@ -83,8 +94,8 @@ class MarketKlinePage extends ConsumerWidget {
'${quote.changeAmount >= 0 ? '+' : ''}${quote.changeAmount.toStringAsFixed(2)} · ${quote.changePercent.toStringAsFixed(2)}%',
style: TextStyle(
color: quote.changeAmount >= 0
? const Color(0xFFC0392B)
: const Color(0xFF2E8B6F),
? Color(palette.up)
: Color(palette.down),
fontSize: 13,
fontWeight: FontWeight.w600,
),
@@ -98,14 +109,15 @@ class MarketKlinePage extends ConsumerWidget {
PrototypePill(
label: p.label,
selected: p == period,
onTap: () => Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (_) => MarketKlinePage(
metalId: metal.id,
periodId: p.id,
onTap: () =>
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (_) => MarketKlinePage(
metalId: metal.id,
periodId: p.id,
),
),
),
),
),
),
],
),
@@ -114,9 +126,19 @@ class MarketKlinePage extends ConsumerWidget {
children: [
_Ohlc('', points.first.open),
const SizedBox(width: 18),
_Ohlc('', points.map((e) => e.high).reduce((a, b) => a > b ? a : b)),
_Ohlc(
'',
points
.map((e) => e.high)
.reduce((a, b) => a > b ? a : b),
),
const SizedBox(width: 18),
_Ohlc('', points.map((e) => e.low).reduce((a, b) => a < b ? a : b)),
_Ohlc(
'',
points
.map((e) => e.low)
.reduce((a, b) => a < b ? a : b),
),
const SizedBox(width: 18),
_Ohlc('', points.last.close),
],
@@ -127,7 +149,9 @@ class MarketKlinePage extends ConsumerWidget {
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: PrototypeLineChart(
values: points.map((p) => p.close).toList(growable: false),
values: points
.map((p) => p.close)
.toList(growable: false),
),
),
),
@@ -135,7 +159,10 @@ class MarketKlinePage extends ConsumerWidget {
Text(
'${quote.basisLabel} · ${_timeLabel(quote.updatedAt)}',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 11, color: cs.mutedForeground),
style: TextStyle(
fontSize: 11,
color: cs.mutedForeground,
),
),
],
),
@@ -161,9 +188,15 @@ class _Ohlc extends StatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: const TextStyle(fontSize: 12, color: Color(0xFF8A8780))),
Text(
label,
style: const TextStyle(fontSize: 12, color: Color(0xFF8A8780)),
),
const SizedBox(height: 2),
Text(value.toStringAsFixed(2), style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
Text(
value.toStringAsFixed(2),
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600),
),
],
);
}
+385 -59
View File
@@ -11,6 +11,8 @@ import '../../../common/widgets/prototype_ui.dart';
import '../application/exchange_calculator_controller.dart';
import '../application/market_controller.dart';
import '../data/market_models.dart';
import '../../profile/application/price_color_theme.dart';
import '../../profile/application/profile_settings_controller.dart';
class MarketPage extends HookConsumerWidget {
const MarketPage({super.key});
@@ -19,23 +21,38 @@ class MarketPage extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final market = ref.watch(marketControllerProvider);
final exchange = ref.watch(exchangeCalculatorControllerProvider);
final gramCtrl = useTextEditingController(text: exchange.gram.toStringAsFixed(2));
final amountCtrl = useTextEditingController(text: exchange.amount.toStringAsFixed(2));
final palette = priceColorPalette(
ref.watch(profileSettingsControllerProvider).priceColorMode,
);
final gramCtrl = useTextEditingController(
text: exchange.gram.toStringAsFixed(2),
);
final amountCtrl = useTextEditingController(
text: exchange.amount.toStringAsFixed(2),
);
final gramFocus = useFocusNode();
final amountFocus = useFocusNode();
final cs = ShadTheme.of(context).colorScheme;
useEffect(() {
if (!gramFocus.hasFocus) {
gramCtrl.text = exchange.gram.toStringAsFixed(
exchange.gram % 1 == 0 ? 0 : 2,
);
}
if (!amountFocus.hasFocus) {
amountCtrl.text = exchange.amount.toStringAsFixed(2);
}
return null;
}, [exchange.gram, exchange.amount, exchange.selectedChannel.id, exchange.metal.id]);
useEffect(
() {
if (!gramFocus.hasFocus) {
gramCtrl.text = exchange.gram.toStringAsFixed(
exchange.gram % 1 == 0 ? 0 : 2,
);
}
if (!amountFocus.hasFocus) {
amountCtrl.text = exchange.amount.toStringAsFixed(2);
}
return null;
},
[
exchange.gram,
exchange.amount,
exchange.selectedChannel.id,
exchange.metal.id,
],
);
return SafeArea(
top: false,
@@ -50,20 +67,27 @@ class MarketPage extends HookConsumerWidget {
children: [
const Text(
'行情',
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600),
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
),
),
const Spacer(),
Container(
width: 30,
height: 30,
decoration: BoxDecoration(
color: const Color(0xFFF7F4EE),
borderRadius: BorderRadius.circular(999),
),
child: const Icon(
Icons.notifications_none_outlined,
size: 18,
color: Color(0xFF9A968D),
GestureDetector(
onTap: () =>
_showPriceAlertSheet(context, market.selectedMetal),
child: Container(
width: 30,
height: 30,
decoration: BoxDecoration(
color: const Color(0xFFF7F4EE),
borderRadius: BorderRadius.circular(999),
),
child: const Icon(
Icons.notifications_none_outlined,
size: 18,
color: Color(0xFF9A968D),
),
),
),
],
@@ -75,15 +99,22 @@ class MarketPage extends HookConsumerWidget {
scrollDirection: Axis.horizontal,
physics: const BouncingScrollPhysics(),
itemCount: MetalType.values.length,
separatorBuilder: (context, index) => const SizedBox(width: 8),
separatorBuilder: (context, index) =>
const SizedBox(width: 8),
itemBuilder: (context, index) {
final metal = MetalType.values[index];
return PrototypePill(
label: metal.label,
selected: metal == market.selectedMetal,
onTap: () {
ref.read(marketControllerProvider.notifier).selectMetal(metal);
ref.read(exchangeCalculatorControllerProvider.notifier).selectMetal(metal);
ref
.read(marketControllerProvider.notifier)
.selectMetal(metal);
ref
.read(
exchangeCalculatorControllerProvider.notifier,
)
.selectMetal(metal);
},
);
},
@@ -108,7 +139,9 @@ class MarketPage extends HookConsumerWidget {
),
const SizedBox(width: 2),
Text(
formatCny(market.quote.spotPrice).replaceFirst('¥', ''),
formatCny(
market.quote.spotPrice,
).replaceFirst('¥', ''),
style: TextStyle(
fontSize: 29,
fontWeight: FontWeight.w600,
@@ -121,7 +154,10 @@ class MarketPage extends HookConsumerWidget {
padding: EdgeInsets.only(left: 4, bottom: 2),
child: Text(
'元/克',
style: TextStyle(fontSize: 12, color: Color(0xFF8A8780)),
style: TextStyle(
fontSize: 12,
color: Color(0xFF8A8780),
),
),
),
],
@@ -129,16 +165,30 @@ class MarketPage extends HookConsumerWidget {
const SizedBox(height: 6),
Row(
children: [
_ChangeChip(amount: market.quote.changeAmount, percent: market.quote.changePercent),
_ChangeChip(
amount: market.quote.changeAmount,
percent: market.quote.changePercent,
upColor: Color(palette.up),
downColor: Color(palette.down),
upBackground: Color(palette.upBackground),
downBackground: Color(palette.downBackground),
),
const SizedBox(width: 8),
Text(
'报价 ${_timeLabel(market.quote.updatedAt)}',
style: const TextStyle(fontSize: 12, color: Color(0xFF8A8780)),
style: const TextStyle(
fontSize: 12,
color: Color(0xFF8A8780),
),
),
const Spacer(),
GestureDetector(
onTap: () {},
child: const Icon(Icons.info_outline, size: 16, color: Color(0xFFB3AFA5)),
child: const Icon(
Icons.info_outline,
size: 16,
color: Color(0xFFB3AFA5),
),
),
],
),
@@ -149,9 +199,12 @@ class MarketPage extends HookConsumerWidget {
_PeriodPill(
label: period.label,
selected: period == market.period,
onTap: () => ref.read(marketControllerProvider.notifier).selectPeriod(period),
onTap: () => ref
.read(marketControllerProvider.notifier)
.selectPeriod(period),
),
if (period != MarketPeriod.values.last) const SizedBox(width: 6),
if (period != MarketPeriod.values.last)
const SizedBox(width: 6),
],
],
),
@@ -165,7 +218,9 @@ class MarketPage extends HookConsumerWidget {
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: PrototypeLineChart(
values: market.points.map((p) => p.close).toList(growable: false),
values: market.points
.map((p) => p.close)
.toList(growable: false),
),
),
),
@@ -177,7 +232,10 @@ class MarketPage extends HookConsumerWidget {
children: [
const Text(
'兑换试算',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600),
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
const Spacer(),
const PrototypePill(label: '多渠道参考', selected: true),
@@ -190,14 +248,19 @@ class MarketPage extends HookConsumerWidget {
scrollDirection: Axis.horizontal,
physics: const BouncingScrollPhysics(),
itemCount: exchange.channels.length,
separatorBuilder: (context, index) => const SizedBox(width: 7),
separatorBuilder: (context, index) =>
const SizedBox(width: 7),
itemBuilder: (context, index) {
final channel = exchange.channels[index];
return PrototypePill(
label: channel.name,
selected: channel.id == exchange.selectedChannel.id,
selected:
channel.id == exchange.selectedChannel.id,
onTap: () => ref
.read(exchangeCalculatorControllerProvider.notifier)
.read(
exchangeCalculatorControllerProvider
.notifier,
)
.selectChannel(channel.id),
);
},
@@ -212,19 +275,30 @@ class MarketPage extends HookConsumerWidget {
leading: '',
onChanged: (value) {
final gram = double.tryParse(value) ?? 0;
ref.read(exchangeCalculatorControllerProvider.notifier).setGram(gram);
ref
.read(
exchangeCalculatorControllerProvider.notifier,
)
.setGram(gram);
},
),
const SizedBox(height: 8),
Center(
child: GestureDetector(
onTap: () => ref.read(exchangeCalculatorControllerProvider.notifier).toggleSwapped(),
onTap: () => ref
.read(
exchangeCalculatorControllerProvider.notifier,
)
.toggleSwapped(),
child: Container(
width: 30,
height: 30,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: cs.border, width: 0.5),
border: Border.all(
color: cs.border,
width: 0.5,
),
shape: BoxShape.circle,
boxShadow: const [
BoxShadow(
@@ -234,7 +308,11 @@ class MarketPage extends HookConsumerWidget {
),
],
),
child: const Icon(Icons.swap_vert, size: 16, color: Color(0xFFB5862A)),
child: const Icon(
Icons.swap_vert,
size: 16,
color: Color(0xFFB5862A),
),
),
),
),
@@ -246,7 +324,11 @@ class MarketPage extends HookConsumerWidget {
leading: '¥',
onChanged: (value) {
final amount = double.tryParse(value) ?? 0;
ref.read(exchangeCalculatorControllerProvider.notifier).setAmount(amount);
ref
.read(
exchangeCalculatorControllerProvider.notifier,
)
.setAmount(amount);
},
),
] else ...[
@@ -257,19 +339,30 @@ class MarketPage extends HookConsumerWidget {
leading: '¥',
onChanged: (value) {
final amount = double.tryParse(value) ?? 0;
ref.read(exchangeCalculatorControllerProvider.notifier).setAmount(amount);
ref
.read(
exchangeCalculatorControllerProvider.notifier,
)
.setAmount(amount);
},
),
const SizedBox(height: 8),
Center(
child: GestureDetector(
onTap: () => ref.read(exchangeCalculatorControllerProvider.notifier).toggleSwapped(),
onTap: () => ref
.read(
exchangeCalculatorControllerProvider.notifier,
)
.toggleSwapped(),
child: Container(
width: 30,
height: 30,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: cs.border, width: 0.5),
border: Border.all(
color: cs.border,
width: 0.5,
),
shape: BoxShape.circle,
boxShadow: const [
BoxShadow(
@@ -279,7 +372,11 @@ class MarketPage extends HookConsumerWidget {
),
],
),
child: const Icon(Icons.swap_vert, size: 16, color: Color(0xFFB5862A)),
child: const Icon(
Icons.swap_vert,
size: 16,
color: Color(0xFFB5862A),
),
),
),
),
@@ -291,19 +388,30 @@ class MarketPage extends HookConsumerWidget {
leading: '',
onChanged: (value) {
final gram = double.tryParse(value) ?? 0;
ref.read(exchangeCalculatorControllerProvider.notifier).setGram(gram);
ref
.read(
exchangeCalculatorControllerProvider.notifier,
)
.setGram(gram);
},
),
],
const SizedBox(height: 10),
Text(
'1 克 ${exchange.metal.label} = ${formatCny(exchange.selectedChannel.pricePerGram)} · ${exchange.selectedChannel.source} · 参考',
style: const TextStyle(fontSize: 12, color: Color(0xFF6E6A60)),
'1 克 ${exchange.metal.label} = ${formatCny(exchange.selectedChannel.pricePerGram)} · ${exchange.selectedChannel.source} · ${_timeLabel(exchange.selectedChannel.updatedAt)} · 参考',
style: const TextStyle(
fontSize: 12,
color: Color(0xFF6E6A60),
),
),
const SizedBox(height: 5),
Text(
exchange.selectedChannel.hint,
style: const TextStyle(fontSize: 11, color: Color(0xFFB3AFA5), height: 1.5),
style: const TextStyle(
fontSize: 11,
color: Color(0xFFB3AFA5),
height: 1.5,
),
),
],
),
@@ -343,13 +451,18 @@ class _ExchangeField extends StatelessWidget {
),
child: Row(
children: [
Text(leading, style: const TextStyle(fontSize: 14, color: Color(0xFF8A8780))),
Text(
leading,
style: const TextStyle(fontSize: 14, color: Color(0xFF8A8780)),
),
const SizedBox(width: 8),
Expanded(
child: TextField(
controller: controller,
focusNode: focusNode,
keyboardType: const TextInputType.numberWithOptions(decimal: true),
keyboardType: const TextInputType.numberWithOptions(
decimal: true,
),
textAlign: TextAlign.right,
decoration: const InputDecoration(
border: InputBorder.none,
@@ -372,7 +485,11 @@ class _ExchangeField extends StatelessWidget {
}
class _PeriodPill extends StatelessWidget {
const _PeriodPill({required this.label, required this.selected, required this.onTap});
const _PeriodPill({
required this.label,
required this.selected,
required this.onTap,
});
final String label;
final bool selected;
@@ -385,10 +502,21 @@ class _PeriodPill extends StatelessWidget {
}
class _ChangeChip extends StatelessWidget {
const _ChangeChip({required this.amount, required this.percent});
const _ChangeChip({
required this.amount,
required this.percent,
required this.upColor,
required this.downColor,
required this.upBackground,
required this.downBackground,
});
final double amount;
final double percent;
final Color upColor;
final Color downColor;
final Color upBackground;
final Color downBackground;
@override
Widget build(BuildContext context) {
@@ -396,7 +524,7 @@ class _ChangeChip extends StatelessWidget {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: positive ? const Color(0xFFFBEDEA) : const Color(0xFFE7F2EE),
color: positive ? upBackground : downBackground,
borderRadius: BorderRadius.circular(999),
),
child: Text(
@@ -404,13 +532,211 @@ class _ChangeChip extends StatelessWidget {
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: positive ? const Color(0xFFC0392B) : const Color(0xFF2E8B6F),
color: positive ? upColor : downColor,
),
),
);
}
}
Future<void> _showPriceAlertSheet(BuildContext context, MetalType metal) async {
var dir = 'up';
final controller = TextEditingController(text: '960.00');
try {
await showModalBottomSheet<void>(
context: context,
backgroundColor: Colors.white,
isScrollControlled: true,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(22)),
),
builder: (ctx) {
return StatefulBuilder(
builder: (ctx, setState) {
return SafeArea(
child: Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.viewInsetsOf(ctx).bottom,
),
child: Padding(
padding: const EdgeInsets.fromLTRB(20, 8, 20, 24),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Center(
child: Container(
width: 38,
height: 4,
margin: const EdgeInsets.only(bottom: 14),
decoration: BoxDecoration(
color: const Color(0xFFE3DFD4),
borderRadius: BorderRadius.circular(999),
),
),
),
const Text(
'设置到价提醒',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 4),
Text(
'${metal.label} 到价时提醒你',
style: const TextStyle(
fontSize: 12,
color: Color(0xFF8A8780),
),
),
const SizedBox(height: 14),
Row(
children: [
Expanded(
child: GestureDetector(
onTap: () => setState(() => dir = 'up'),
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 10,
),
decoration: BoxDecoration(
color: dir == 'up'
? const Color(0xFFF6ECD6)
: Colors.white,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: dir == 'up'
? const Color(0xFFE3D6B4)
: const Color(0xFFECEAE3),
width: 0.5,
),
),
child: const Text(
'涨到',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
),
),
),
),
),
const SizedBox(width: 8),
Expanded(
child: GestureDetector(
onTap: () => setState(() => dir = 'down'),
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 10,
),
decoration: BoxDecoration(
color: dir == 'down'
? const Color(0xFFF6ECD6)
: Colors.white,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: dir == 'down'
? const Color(0xFFE3D6B4)
: const Color(0xFFECEAE3),
width: 0.5,
),
),
child: const Text(
'跌到',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
),
),
),
),
),
],
),
const SizedBox(height: 14),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 13,
vertical: 10,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(13),
border: Border.all(
color: const Color(0xFFE3D6B4),
width: 0.5,
),
),
child: Row(
children: [
const Text(
'¥',
style: TextStyle(
fontSize: 14,
color: Color(0xFF8A8780),
),
),
const SizedBox(width: 8),
Expanded(
child: TextField(
controller: controller,
keyboardType:
const TextInputType.numberWithOptions(
decimal: true,
),
textAlign: TextAlign.right,
decoration: const InputDecoration(
border: InputBorder.none,
isDense: true,
),
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
),
const SizedBox(width: 8),
const Text(
'元/克',
style: TextStyle(
fontSize: 13,
color: Color(0xFF8A8780),
),
),
],
),
),
const SizedBox(height: 16),
FilledButton(
onPressed: () {
Navigator.of(ctx).pop();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'已设到价提醒 · $metal ${dir == 'up' ? '涨到' : '跌到'} ¥${controller.text}',
),
),
);
},
child: const Text('完成'),
),
],
),
),
),
);
},
);
},
);
} finally {
controller.dispose();
}
}
String _timeLabel(DateTime value) {
return '${value.hour.toString().padLeft(2, '0')}:${value.minute.toString().padLeft(2, '0')}';
}