1- // ... existing code ...
2-
31import 'package:flutter/cupertino.dart' ;
42import 'package:flutter/material.dart' ;
53
64import '../../database/database.dart' ;
75import '../../database/database_manager.dart' ;
86import 'TextItemData.dart' ;
97import 'dart:convert' ;
8+ import '../BaseDisplayWidget.dart' ;
9+ import 'package:animated_text_kit/animated_text_kit.dart' ; // 导入 animated_text_kit 库
10+
1011
1112/**
1213 * 文字区域显示组件
1314 */
14- class TextWidgetBuilder {
15- static Future < Widget > buildTextWidget (
16- int programId, Map <String , dynamic > item) async {
15+ class TextWidgetBuilder extends BaseDisplayWidget {
16+ @override
17+ Future < Widget > buildWidget ( int programId, Map <String , dynamic > item) async {
1718 final DatabaseManager _dbManager = DatabaseManager ();
1819 String itemID = item['id' ];
1920 print ("构建文字区域显示组件 模板区域id: ${itemID }" );
2021 try {
21- //根据programID和模板区域id查询节目中这个模板区域的配置
22+ // 根据programID和模板区域id查询节目中这个模板区域的配置
2223 ProgramItem ? programItemData = await _dbManager
2324 .getProgramItemByProgramIdAndItemId (programId, itemID);
2425 print ("查询到的节目中这个模板区域的配置:${programItemData ?.toJson ()}" );
@@ -44,6 +45,10 @@ class TextWidgetBuilder {
4445 ),
4546 );
4647 }
48+ // final double devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
49+ // final double flutterFontSize = webFontSize / devicePixelRatio;
50+ print ("文字大小:${textItemData .textFontSize } 动画效果:${textItemData .textAnimalType } 字体:${textItemData .textFontFamily }" );
51+
4752
4853 // 解析颜色
4954 Color parseColor (String colorStr) {
@@ -110,7 +115,7 @@ class TextWidgetBuilder {
110115 }
111116 }
112117
113- //居中设置
118+ // 居中设置
114119 // Function to parse text alignment
115120 TextAlign parseTextAlign (String align) {
116121 switch (align.toLowerCase ()) {
@@ -125,30 +130,108 @@ class TextWidgetBuilder {
125130 }
126131 }
127132
133+ final textStyle = TextStyle (
134+ color: parseColor (textItemData.textColor),
135+ fontSize: double .tryParse ((textItemData.textFontSize).toString ()) ?? 20 ,
136+ fontFamily: textItemData.textFontFamily,
137+ fontWeight: parseFontWeight (textItemData.textWeight),
138+ fontStyle: parseFontStyle (textItemData.textStyle),
139+ decoration: parseUnderline (textItemData.textUnderline),
140+ );
141+
142+ List <AnimatedText > getAnimatedTexts (String animalType,String textContent,String textAlign) {
143+ switch (animalType) {
144+ case 'none' :
145+ print ("无动画效果" );
146+ return [
147+ // 无动画效果,直接使用普通 Text
148+ TyperAnimatedText (
149+ textContent,
150+ speed: const Duration (milliseconds: 0 ),
151+ textAlign: parseTextAlign (textAlign),
152+ ),
153+ ];
154+ case 'Fade' :
155+ print ("淡入淡出效果" );
156+ return [
157+ FadeAnimatedText (
158+ textContent,
159+ duration: const Duration (seconds: 2 ),
160+ textAlign: parseTextAlign (textAlign),
161+ ),
162+ ];
163+ case 'Typer' :
164+ print ("打字效果" );
165+ return [
166+ TyperAnimatedText (
167+ textContent,
168+ speed: const Duration (milliseconds: 100 ),
169+ textAlign: parseTextAlign (textAlign),
170+ ),
171+ ];
172+ case 'Scale' :
173+ print ("缩放效果" );
174+ return [
175+ ScaleAnimatedText (
176+ textContent,
177+ textAlign: parseTextAlign (textAlign),
178+ duration: const Duration (milliseconds: 2000 ),
179+ scalingFactor: 0.5 ,
180+ ),
181+ ];
182+ case 'Flick' :
183+ print ("闪烁效果" );
184+ return [
185+ FlickerAnimatedText (
186+ textContent,
187+ textStyle: textStyle,
188+ textAlign: parseTextAlign (textAlign),
189+ ),
190+ ];
191+ case 'Colorize' :
192+ print ("颜色变化效果" );
193+ return [
194+ ColorizeAnimatedText (
195+ textContent,
196+ colors: [
197+ Colors .purple,
198+ Colors .blue,
199+ Colors .yellow,
200+ Colors .red,
201+ ],
202+ textStyle: textStyle,
203+ textAlign: parseTextAlign (textAlign),
204+ ),
205+ ];
206+ default :
207+ return [
208+ // 无动画效果,直接使用普通 Text
209+ TyperAnimatedText (
210+ textContent,
211+ speed: const Duration (milliseconds: 0 ),
212+ textAlign: parseTextAlign (textAlign),
213+ ),
214+ ];
215+ }
216+ }
217+
128218 return Container (
129219 color: parseColor (textItemData.textBGColor),
130220 child: Align (
131- alignment: Alignment .center,
132221 child: SizedBox (
133222 width: double .infinity,
134- child: Text (
135- textItemData.textContent,
136- style: TextStyle (
137- color: parseColor (textItemData.textColor),
138- fontSize: double .tryParse (textItemData.textFontSize.toString ()) ?? 20 ,
139- fontFamily: textItemData.textFontFamily,
140- fontWeight: parseFontWeight (textItemData.textWeight),
141- fontStyle: parseFontStyle (textItemData.textStyle),
142- decoration: parseUnderline (textItemData.textUnderline),
223+ child: DefaultTextStyle (
224+ style: textStyle,
225+ child: AnimatedTextKit (
226+ repeatForever: true ,
227+ animatedTexts: getAnimatedTexts (textItemData.textAnimalType,textItemData.textContent,textItemData.align),
143228 ),
144- textAlign: parseTextAlign (textItemData.align),
145229 ),
146230 ),
147231 ),
148232 );
149-
150233 } catch (e) {
151- print ("Error in buildTextWidget : $e " );
234+ print ("Error in buildWidget : $e " );
152235 return Container (
153236 color: Colors .black,
154237 alignment: Alignment .center,
@@ -159,4 +242,8 @@ class TextWidgetBuilder {
159242 );
160243 }
161244 }
162- }
245+ @override
246+ void dispose () {
247+ print ("Text Area Release" );
248+ }
249+ }
0 commit comments