flutterdartgif

how to prevent gif reset when the playback finishes in flutter


I'm using gif_view to control gif in flutter and when it finishes playing, it is coming to initial position, but I want it in last position itself.

import 'package:gif_view/gif_view.dart';
final controller = GifController(loop: false);
GifView.asset(
   "assets/1.gif",
   controller: controller,
   progress: const CircularProgressIndicator(),
),

even it is taking lot of time to load, so I want to fix this also

I'm expecting fix to both loading gif quickly and gif should not reset a after playing completely.


Solution

  • I followed this method for time being and worked for me to avoid reset.

    class _GifViewer extends State<GifViwer> {
      bool isPaused = false;
      late GifController controller;
    
      @override
      void initState() {
        controller = GifController(
            loop: false,
            onFrame: (value) {
              if (value == 100)   //<---------- last frame value - 1 
              {
                setState(() {
                  isPaused = true;
                });
              }
            });
    
        super.initState();
      }
    
      @override
      Widget build(BuildContext context) {
        if (isPaused) {
          controller.pause();
        }
        return Scaffold(
          body: GifView.asset(
            path,
            controller: controller,
          ),
          // }),
        );
      }
    }