import 'package:flutter/cupertino.dart';
import 'package:gif_view/gif_view.dart';

class GifLoaderContainer extends StatefulWidget {
  bool barrierDismissible;

  GifLoaderContainer({this.barrierDismissible = true});

  @override
  _GifLoaderContainerState createState() => _GifLoaderContainerState();
}

class _GifLoaderContainerState extends State<GifLoaderContainer> with TickerProviderStateMixin {
  late GifController controller;

  @override
  void initState() {
    controller = GifController();

    WidgetsBinding.instance.addPostFrameCallback((_) {
      try {
        controller = GifController();
        //  controller.repeat(min: 0, max: 11, period: Duration(milliseconds: 750), reverse: true);
      } catch (ex) {}
    });
    super.initState();
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async {
        return widget.barrierDismissible;
      },
      child: Center(
        //progress-loading.gif
        child: Container(
          // margin: EdgeInsets.only(bottom: 40),
          child: GifView(
            controller: controller,
            image: AssetImage("assets/images/progress-loading-red.gif"), //NetworkImage("http://img.mp.itc.cn/upload/20161107/5cad975eee9e4b45ae9d3c1238ccf91e.jpg"),
          ),
        ),
      ),
    );
  }
}
