From de2aed70e40a4ec98129e9eee57b999d56537056 Mon Sep 17 00:00:00 2001 From: AmirrezaChegini Date: Fri, 12 Dec 2025 11:40:47 +0330 Subject: [PATCH] add Gif --- lib/core/widgets/answer_box/answer_box.dart | 4 ++++ .../widgets/answer_box/answer_box_show.dart | 2 ++ .../answer_box/styles/picture_box.dart | 20 +++++++++++++++---- .../ui/screens/question_screen.dart | 2 ++ pubspec.lock | 8 ++++++++ pubspec.yaml | 3 ++- 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/core/widgets/answer_box/answer_box.dart b/lib/core/widgets/answer_box/answer_box.dart index 9f0f510..a9b672a 100644 --- a/lib/core/widgets/answer_box/answer_box.dart +++ b/lib/core/widgets/answer_box/answer_box.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:gif/gif.dart'; import 'package:hadi_hoda_flutter/common_ui/resources/my_assets.dart'; import 'package:hadi_hoda_flutter/common_ui/resources/my_spaces.dart'; import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart'; @@ -15,6 +16,7 @@ class AnswerBox extends StatefulWidget { required this.index, this.onTap, this.onNotifTap, + this.autostart = Autostart.no, }); final AnswerEntity answer; @@ -22,6 +24,7 @@ class AnswerBox extends StatefulWidget { final void Function(bool isCorrect, int correctAnswer)? onTap; final int index; final Function(AnswerEntity answer)? onNotifTap; + final Autostart autostart; @override State createState() => _AnswerBoxState(); @@ -56,6 +59,7 @@ class _AnswerBoxState extends State { index: widget.index, image: widget.answer.image ?? '', correctAnswer: widget.correctAnswer, + autostart: widget.autostart, onTap: () { widget.onNotifTap?.call(widget.answer); }, diff --git a/lib/core/widgets/answer_box/answer_box_show.dart b/lib/core/widgets/answer_box/answer_box_show.dart index b09f4c5..ee524fc 100644 --- a/lib/core/widgets/answer_box/answer_box_show.dart +++ b/lib/core/widgets/answer_box/answer_box_show.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:gif/gif.dart'; import 'package:hadi_hoda_flutter/common_ui/resources/my_assets.dart'; import 'package:hadi_hoda_flutter/common_ui/resources/my_spaces.dart'; import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart'; @@ -33,6 +34,7 @@ class AnswerBoxShow extends StatelessWidget { selected: false, index: index, image: answer.image ?? '', + autostart: Autostart.once, correctAnswer: 0, ), Positioned( diff --git a/lib/core/widgets/answer_box/styles/picture_box.dart b/lib/core/widgets/answer_box/styles/picture_box.dart index 164bb9e..b5d34f5 100644 --- a/lib/core/widgets/answer_box/styles/picture_box.dart +++ b/lib/core/widgets/answer_box/styles/picture_box.dart @@ -1,10 +1,12 @@ import 'dart:io'; import 'package:flutter/material.dart'; +import 'package:gif/gif.dart'; import 'package:hadi_hoda_flutter/common_ui/resources/my_assets.dart'; import 'package:hadi_hoda_flutter/common_ui/resources/my_colors.dart'; import 'package:hadi_hoda_flutter/common_ui/resources/my_spaces.dart'; import 'package:hadi_hoda_flutter/common_ui/resources/my_text_style.dart'; +import 'package:hadi_hoda_flutter/core/utils/screen_size.dart'; import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart'; import 'package:hadi_hoda_flutter/core/widgets/images/my_image.dart'; @@ -16,6 +18,7 @@ class AnswerPictureBox extends StatelessWidget { required this.index, required this.correctAnswer, this.onTap, + this.autostart = Autostart.no, }); final bool selected; @@ -23,6 +26,7 @@ class AnswerPictureBox extends StatelessWidget { final int index; final int correctAnswer; final VoidCallback? onTap; + final Autostart autostart; @override Widget build(BuildContext context) { @@ -41,16 +45,24 @@ class AnswerPictureBox extends StatelessWidget { switchInCurve: Curves.linear, switchOutCurve: Curves.linear, child: selected && (index != correctAnswer) ? - Image.file( + Gif( key: Key('1'), - File(image), + width: context.widthScreen, + height: context.heightScreen, + image: FileImage(File(image)), + fps: 30, + autostart: autostart, fit: BoxFit.cover, color: MyColors.black, colorBlendMode: BlendMode.color, ) : - Image.file( + Gif( key: Key('2'), - File(image), + width: context.widthScreen, + height: context.heightScreen, + image: FileImage(File(image)), + fps: 30, + autostart: autostart, fit: BoxFit.cover, ), transitionBuilder: (child, animation) => diff --git a/lib/features/question/presentation/ui/screens/question_screen.dart b/lib/features/question/presentation/ui/screens/question_screen.dart index 21ddf89..d0d1afb 100644 --- a/lib/features/question/presentation/ui/screens/question_screen.dart +++ b/lib/features/question/presentation/ui/screens/question_screen.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:gif/gif.dart'; import 'package:hadi_hoda_flutter/common_ui/resources/my_assets.dart'; import 'package:hadi_hoda_flutter/common_ui/resources/my_colors.dart'; import 'package:hadi_hoda_flutter/common_ui/resources/my_spaces.dart'; @@ -102,6 +103,7 @@ class _QuestionScreenState extends State with TickerProviderStat correctAnswer: 0, index: 0, image: state.currentQuestion?.image ?? '', + autostart: Autostart.once, ), ), ), diff --git a/pubspec.lock b/pubspec.lock index 3609dd0..f14a07c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -333,6 +333,14 @@ packages: url: "https://pub.dev" source: hosted version: "8.2.0" + gif: + dependency: "direct main" + description: + name: gif + sha256: ade95694f1471da737922806818ffade2814d1d7f8d10af38ebcf36ace012bc0 + url: "https://pub.dev" + source: hosted + version: "2.3.0" glob: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 82c75e0..98a157d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: hadi_hoda_flutter description: "A new Flutter project." publish_to: 'none' -version: 0.1.8+1 +version: 0.1.9+1 environment: sdk: ^3.9.2 @@ -20,6 +20,7 @@ dependencies: flutter_localizations: sdk: flutter get_it: ^8.2.0 + gif: ^2.3.0 go_router: ^16.1.0 hive: ^2.2.3 intl: ^0.20.2