// seg_switch.dart — 分段开关(镜像 design/prototype atoms .segswitch)。 // 一排等宽选项,每项 leading 图标 + 文字;选中态 surface 底 + 柔和阴影 + fg1, // 未选 fg2;容器 bg-subtle + border + full 圆角。渠道/币种/主题等二选一场景通用。 import 'package:flutter/material.dart'; import '../pangolin_theme.dart'; /// 单个分段项:图标 + 文案。 typedef SegOption = ({IconData icon, String label}); class SegSwitch extends StatelessWidget { const SegSwitch({ super.key, required this.options, required this.selectedIndex, required this.onChanged, }); final List options; final int selectedIndex; final ValueChanged onChanged; @override Widget build(BuildContext context) { final c = context.pangolin; return Container( // .segswitch:bg-subtle + border + full 圆角 + space-1 内边距/间隙 padding: const EdgeInsets.all(4), decoration: BoxDecoration( color: c.bgSubtle, border: Border.all(color: c.border), borderRadius: BorderRadius.circular(PangolinRadius.full), ), child: Row( children: [ for (var i = 0; i < options.length; i++) ...[ if (i > 0) const SizedBox(width: 4), Expanded(child: _opt(c, i, options[i])), ], ], ), ); } Widget _opt(PangolinScheme c, int i, SegOption o) { final active = i == selectedIndex; return GestureDetector( behavior: HitTestBehavior.opaque, onTap: active ? null : () => onChanged(i), child: AnimatedContainer( duration: const Duration(milliseconds: 140), curve: Curves.easeOut, padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), decoration: BoxDecoration( // .segswitch-opt.is-active:surface 底 + shadow-sm;未选透明 color: active ? c.surface : Colors.transparent, borderRadius: BorderRadius.circular(PangolinRadius.full), boxShadow: active ? PangolinShadow.sm : null, ), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(o.icon, size: 16, color: active ? c.fg1 : c.fg2), const SizedBox(width: 8), Flexible( child: Text( o.label, maxLines: 1, overflow: TextOverflow.ellipsis, style: PangolinText.sm.copyWith( color: active ? c.fg1 : c.fg2, fontWeight: FontWeight.w600, ), ), ), ], ), ), ); } }