File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed
local_ads_management/view Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import 'package:data_table_2/data_table_2.dart';
44import 'package:flutter/material.dart' ;
55import 'package:flutter/services.dart' ;
66import 'package:flutter_bloc/flutter_bloc.dart' ;
7+ import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/app_localizations.dart' ;
78import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart' ;
89import 'package:flutter_news_app_web_dashboard_full_source_code/local_ads_management/bloc/local_ads_management_bloc.dart' ;
910import 'package:flutter_news_app_web_dashboard_full_source_code/router/routes.dart' ;
Original file line number Diff line number Diff line change 1+ import 'package:core/core.dart' ;
2+
3+ /// Defines extension methods for [LocalAd] to convert its `adType` string
4+ /// to the corresponding [AdType] enum.
5+ extension LocalAdToAdType on LocalAd {
6+ /// Converts the `adType` string of this [LocalAd] instance to an [AdType] enum.
7+ ///
8+ /// Throws a [StateError] if the `adType` string does not correspond to a
9+ /// valid [AdType] enum value.
10+ AdType toAdType () {
11+ switch (adType) {
12+ case 'native' :
13+ return AdType .native ;
14+ case 'banner' :
15+ return AdType .banner;
16+ case 'interstitial' :
17+ return AdType .interstitial;
18+ case 'video' :
19+ return AdType .video;
20+ default :
21+ throw StateError ('Unknown adType: $adType ' );
22+ }
23+ }
24+ }
Original file line number Diff line number Diff line change 1- extension StringTruncate on String {
1+ /// Extension on [String] to provide truncation and capitalization utilities.
2+ extension StringX on String {
3+ /// Truncates the string to a specified [maxLength] .
4+ ///
5+ /// If the string's length exceeds [maxLength] , it is truncated and
6+ /// '...' is appended.
27 String truncate (int maxLength) {
38 if (length <= maxLength) {
49 return this ;
510 }
611 return '${substring (0 , maxLength )}...' ;
712 }
13+
14+ /// Capitalizes the first letter of the string.
15+ ///
16+ /// Returns the original string if it is empty.
17+ String capitalize () {
18+ if (isEmpty) {
19+ return this ;
20+ }
21+ return '${this [0 ].toUpperCase ()}${substring (1 )}' ;
22+ }
823}
You can’t perform that action at this time.
0 commit comments