fix: K线图技术指标切换重构,简化代码逻辑
This commit is contained in:
@@ -271,13 +271,6 @@ class ChartPage extends StatelessWidget {
|
||||
/// 技术指标切换
|
||||
Widget _buildIndicatorTabs(BuildContext context, ChartProvider provider) {
|
||||
final colorScheme = context.colors;
|
||||
final indicators = [
|
||||
{'key': 'MA', 'label': 'MA', 'value': provider.indicators.showMA},
|
||||
{'key': 'EMA', 'label': 'EMA', 'value': provider.indicators.showEMA},
|
||||
{'key': 'BOLL', 'label': 'BOLL', 'value': provider.indicators.showBOLL},
|
||||
{'key': 'VOL', 'label': 'VOL', 'value': provider.indicators.showVOL},
|
||||
{'key': 'MACD', 'label': 'MACD', 'value': provider.indicators.showMACD},
|
||||
];
|
||||
|
||||
return Container(
|
||||
height: 36,
|
||||
@@ -291,74 +284,92 @@ class ChartPage extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: indicators.map((item) {
|
||||
final isSelected = item['value'] as bool;
|
||||
final key = item['key'] as String;
|
||||
final label = item['label'] as String;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: AppSpacing.xs),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
switch (key) {
|
||||
case 'MA':
|
||||
provider.updateIndicators(
|
||||
provider.indicators.copyWith(showMA: !isSelected),
|
||||
);
|
||||
break;
|
||||
case 'EMA':
|
||||
provider.updateIndicators(
|
||||
provider.indicators.copyWith(showEMA: !isSelected),
|
||||
);
|
||||
break;
|
||||
case 'BOLL':
|
||||
provider.updateIndicators(
|
||||
provider.indicators.copyWith(showBOLL: !isSelected),
|
||||
);
|
||||
break;
|
||||
case 'VOL':
|
||||
provider.updateIndicators(
|
||||
provider.indicators.copyWith(showVOL: !isSelected),
|
||||
);
|
||||
break;
|
||||
case 'MACD':
|
||||
provider.updateIndicators(
|
||||
provider.indicators.copyWith(showMACD: !isSelected),
|
||||
);
|
||||
break;
|
||||
}
|
||||
},
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.xs,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? colorScheme.primary.withValues(alpha: 0.1)
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
border: Border.all(
|
||||
color: isSelected
|
||||
? colorScheme.primary
|
||||
: colorScheme.outlineVariant.withValues(alpha: 0.3),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: AppTextStyles.labelSmall(context).copyWith(
|
||||
color: isSelected
|
||||
? colorScheme.primary
|
||||
: colorScheme.onSurfaceVariant,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400,
|
||||
),
|
||||
),
|
||||
),
|
||||
children: [
|
||||
_buildIndicatorChip(
|
||||
context,
|
||||
label: 'MA',
|
||||
isSelected: provider.indicators.showMA,
|
||||
onTap: () => provider.updateIndicators(
|
||||
provider.indicators.copyWith(showMA: !provider.indicators.showMA),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
_buildIndicatorChip(
|
||||
context,
|
||||
label: 'EMA',
|
||||
isSelected: provider.indicators.showEMA,
|
||||
onTap: () => provider.updateIndicators(
|
||||
provider.indicators.copyWith(showEMA: !provider.indicators.showEMA),
|
||||
),
|
||||
),
|
||||
_buildIndicatorChip(
|
||||
context,
|
||||
label: 'BOLL',
|
||||
isSelected: provider.indicators.showBOLL,
|
||||
onTap: () => provider.updateIndicators(
|
||||
provider.indicators.copyWith(showBOLL: !provider.indicators.showBOLL),
|
||||
),
|
||||
),
|
||||
_buildIndicatorChip(
|
||||
context,
|
||||
label: 'VOL',
|
||||
isSelected: provider.indicators.showVOL,
|
||||
onTap: () => provider.updateIndicators(
|
||||
provider.indicators.copyWith(showVOL: !provider.indicators.showVOL),
|
||||
),
|
||||
),
|
||||
_buildIndicatorChip(
|
||||
context,
|
||||
label: 'MACD',
|
||||
isSelected: provider.indicators.showMACD,
|
||||
onTap: () => provider.updateIndicators(
|
||||
provider.indicators.copyWith(showMACD: !provider.indicators.showMACD),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIndicatorChip(
|
||||
BuildContext context, {
|
||||
required String label,
|
||||
required bool isSelected,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
final colorScheme = context.colors;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: AppSpacing.xs),
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.xs,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? colorScheme.primary.withValues(alpha: 0.1)
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
border: Border.all(
|
||||
color: isSelected
|
||||
? colorScheme.primary
|
||||
: colorScheme.outlineVariant.withValues(alpha: 0.3),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: AppTextStyles.labelSmall(context).copyWith(
|
||||
color: isSelected
|
||||
? colorScheme.primary
|
||||
: colorScheme.onSurfaceVariant,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user