flutter_gif 0.0.1 copy "flutter_gif: ^0.0.1" to clipboard
flutter_gif: ^0.0.1 copied to clipboard

outdated

gif image widget help to control gif progress,speed,repeat frames .

example/lib/main.dart

import 'dart:convert';

import 'package:example/consts.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gif/flutter_gif.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

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

class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
  late FlutterGifController controller1, controller2, controller3, controller4;

  @override
  void initState() {
    controller1 = FlutterGifController(vsync: this);
    controller2 = FlutterGifController(vsync: this);
    controller4 = FlutterGifController(vsync: this);
    WidgetsBinding.instance?.addPostFrameCallback((_) {
      controller1.repeat(
        min: 0,
        max: 53,
        period: const Duration(milliseconds: 200),
      );
    });
    WidgetsBinding.instance?.addPostFrameCallback((_) {
      controller2.repeat(
        min: 0,
        max: 13,
        period: const Duration(milliseconds: 200),
      );
      controller4.repeat(
        min: 0,
        max: 13,
        period: const Duration(milliseconds: 200),
      );
    });
    controller3 = FlutterGifController(
      vsync: this,
      duration: const Duration(milliseconds: 200),
      reverseDuration: const Duration(milliseconds: 200),
    );
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
          bottom: const TabBar(
            tabs: [
              Tab(
                child: Text("不同类型图片"),
              ),
              Tab(
                child: Text("控制方式"),
              )
            ],
          ),
        ),
        body: TabBarView(
          children: [
            ListView(
              children: [
                const Text("资源"),
                GifImage(
                  controller: controller1,
                  image: const AssetImage("images/animate.gif"),
                ),
                const Text("网络"),
                GifImage(
                  controller: controller2,
                  image: const NetworkImage(
                      "http://img.mp.itc.cn/upload/20161107/5cad975eee9e4b45ae9d3c1238ccf91e.jpg"),
                ),
                const Text("内存"),
                GifImage(
                  controller: controller4,
                  image: MemoryImage(base64Decode(base64GifUrl)),
                )
              ],
            ),
            Column(
              children: [
                Row(
                  children: [
                    ElevatedButton(
                      child: const Text("无限循环"),
                      onPressed: () {
                        controller3.repeat(
                            min: 0,
                            max: 25,
                            period: const Duration(milliseconds: 500));
                      },
                    ),
                    ElevatedButton(
                      child: const Text("暂停"),
                      onPressed: () {
                        controller3.stop();
                      },
                    ),
                    ElevatedButton(
                      child: const Text("播放到末尾一次"),
                      onPressed: () {
                        controller3.animateTo(52,
                            duration: const Duration(milliseconds: 1000));
                      },
                    )
                  ],
                ),
                Slider(
                  onChanged: (v) {
                    controller3.value = v;
                    setState(() {});
                  },
                  max: 53,
                  min: 0,
                  value: controller3.value,
                ),
                GifImage(
                  controller: controller3,
                  image: const AssetImage("images/animate.gif"),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}
54
likes
0
pub points
95%
popularity

Publisher

verified publisherflutter-doctor.com

gif image widget help to control gif progress,speed,repeat frames .

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on flutter_gif