|
| 1 | +import 'package:core/core.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:flutter_bloc/flutter_bloc.dart'; |
| 4 | +import 'package:flutter_news_app_web_dashboard_full_source_code/app_configuration/bloc/app_configuration_bloc.dart'; |
| 5 | +import 'package:flutter_news_app_web_dashboard_full_source_code/app_configuration/widgets/feed_decorator_form.dart'; |
| 6 | +import 'package:flutter_news_app_web_dashboard_full_source_code/app_configuration/widgets/user_preference_limits_form.dart'; |
| 7 | +import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart'; |
| 8 | +import 'package:flutter_news_app_web_dashboard_full_source_code/shared/extensions/feed_decorator_type_l10n.dart'; |
| 9 | +import 'package:ui_kit/ui_kit.dart'; |
| 10 | + |
| 11 | +/// {@template feed_configuration_tab} |
| 12 | +/// A widget representing the "Feed" tab in the App Configuration page. |
| 13 | +/// |
| 14 | +/// This tab allows configuration of user content limits and feed decorators. |
| 15 | +/// {@endtemplate} |
| 16 | +class FeedConfigurationTab extends StatelessWidget { |
| 17 | + /// {@macro feed_configuration_tab} |
| 18 | + const FeedConfigurationTab({ |
| 19 | + required this.remoteConfig, |
| 20 | + required this.onConfigChanged, |
| 21 | + super.key, |
| 22 | + }); |
| 23 | + |
| 24 | + /// The current [RemoteConfig] object. |
| 25 | + final RemoteConfig remoteConfig; |
| 26 | + |
| 27 | + /// Callback to notify parent of changes to the [RemoteConfig]. |
| 28 | + final ValueChanged<RemoteConfig> onConfigChanged; |
| 29 | + |
| 30 | + @override |
| 31 | + Widget build(BuildContext context) { |
| 32 | + final l10n = AppLocalizationsX(context).l10n; |
| 33 | + |
| 34 | + return ListView( |
| 35 | + padding: const EdgeInsets.all(AppSpacing.lg), |
| 36 | + children: [ |
| 37 | + // Top-level ExpansionTile for User Content Limits |
| 38 | + ExpansionTile( |
| 39 | + title: Text(l10n.userContentLimitsTitle), |
| 40 | + childrenPadding: const EdgeInsets.symmetric( |
| 41 | + horizontal: AppSpacing.xxl, |
| 42 | + ), |
| 43 | + children: [ |
| 44 | + UserPreferenceLimitsForm( |
| 45 | + remoteConfig: remoteConfig, |
| 46 | + onConfigChanged: onConfigChanged, |
| 47 | + ), |
| 48 | + ], |
| 49 | + ), |
| 50 | + const SizedBox(height: AppSpacing.lg), |
| 51 | + // Description for Feed Decorators section |
| 52 | + Text( |
| 53 | + l10n.feedDecoratorsDescription, |
| 54 | + style: Theme.of(context).textTheme.bodySmall?.copyWith( |
| 55 | + color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7), |
| 56 | + ), |
| 57 | + ), |
| 58 | + const SizedBox(height: AppSpacing.lg), |
| 59 | + // Individual ExpansionTiles for each Feed Decorator |
| 60 | + for (final decoratorType in FeedDecoratorType.values) |
| 61 | + Padding( |
| 62 | + padding: const EdgeInsets.only(bottom: AppSpacing.md), |
| 63 | + child: ExpansionTile( |
| 64 | + title: Text(decoratorType.l10n(context)), // Use localized decorator name |
| 65 | + childrenPadding: const EdgeInsets.symmetric( |
| 66 | + horizontal: AppSpacing.xxl, |
| 67 | + ), |
| 68 | + children: [ |
| 69 | + FeedDecoratorForm( |
| 70 | + decoratorType: decoratorType, |
| 71 | + remoteConfig: remoteConfig.copyWith( |
| 72 | + feedDecoratorConfig: |
| 73 | + Map.from(remoteConfig.feedDecoratorConfig)..putIfAbsent( |
| 74 | + decoratorType, |
| 75 | + () => FeedDecoratorConfig( |
| 76 | + category: |
| 77 | + decoratorType == FeedDecoratorType.suggestedTopics || |
| 78 | + decoratorType == FeedDecoratorType.suggestedSources |
| 79 | + ? FeedDecoratorCategory.contentCollection |
| 80 | + : FeedDecoratorCategory.callToAction, |
| 81 | + enabled: false, |
| 82 | + visibleTo: const {}, |
| 83 | + itemsToDisplay: |
| 84 | + decoratorType == FeedDecoratorType.suggestedTopics || |
| 85 | + decoratorType == FeedDecoratorType.suggestedSources |
| 86 | + ? 0 |
| 87 | + : null, |
| 88 | + ), |
| 89 | + ), |
| 90 | + ), |
| 91 | + onConfigChanged: onConfigChanged, |
| 92 | + ), |
| 93 | + ], |
| 94 | + ), |
| 95 | + ), |
| 96 | + ], |
| 97 | + ); |
| 98 | + } |
| 99 | +} |
0 commit comments