You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
314 KiB

import 'dart:convert';
import 'package:flutter/cupertino.dart';
5 years ago
import 'package:flutter/material.dart';
import 'package:flutter_gifimage/flutter_gifimage.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
const base64_url = "R0lGODlhSgGHAPUAAP///wAAAERwxFSAzGyY1Jy43MTQ7Nzo/Pz4/PioOPhQCPh4EPjQWPjgiPjwwPj4+PAwAOggAP/4//+lWv+MQv/GY//ee//nrf/v1v9zKe9SCM5KCKU5CPZ7Of97CP+VEP++Kv/OOf/fSv/nYv/3g///tf+tIf9qAPdSAP//3fdBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAgGAAAAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAASgGHAAAG/kCAcEgsGo/IpHLJbDqf0Kh0Sq1ar9isdsvter/gsHhMLpvP6LR6zW673/C4fE6v2+/4vH7P7/v/gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8DBwsPExcbHyMnKy8zNzs/Q0dLT1NXW19jZ2tvc3d7f4OF/AQHi5kPk5efm5Ouy6els7Vbw8+6P9fVq8VP58PeN/OlLww+KwH8AEx0ciMaek4UIE2bJZwYiwzMOl1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56YLz06veyz1v3emivwf5rhxkvwWfyceNefffZtRdmxYn0lnf9/CZYggoq91yBRkH4oHbtZUUfEBKe0+FmssWnlX+QYRghiSI6daBZJp6oIoLdlNfiBcLlFqKMYxAYIzg5/qDhhT2idqMIQUp3pIFDMpZkiT/y4OB/L6r
5 years ago
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
GifController controller1,controller2,controller3,controller4;
5 years ago
@override
void initState() {
// TODO: implement initState
controller1 = GifController(vsync: this);
controller2 = GifController(vsync: this);
controller4= GifController(vsync: this);
5 years ago
WidgetsBinding.instance.addPostFrameCallback((_){
controller1.repeat(min: 0,max: 53,period: Duration(milliseconds: 200));
});
WidgetsBinding.instance.addPostFrameCallback((_){
controller2.repeat(min: 0,max: 13,period: Duration(milliseconds: 200));
controller4.repeat(min: 0,max: 13,period: Duration(milliseconds: 200));
});
controller3 = GifController(vsync: this,duration: Duration(milliseconds: 200),reverseDuration: Duration(milliseconds: 200));
5 years ago
super.initState();
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return DefaultTabController(length: 2,
child: Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
bottom: TabBar(
tabs: <Widget>[Tab(child: Text("不同类型图片"),),Tab(child: Text("控制方式"),)],
),
5 years ago
),
body: TabBarView(
children: <Widget>[
ListView(
children: <Widget>[
Text("资源"),
GifImage(
controller: controller1,
image: AssetImage("images/animate.gif"),
),
Text("网络"),
GifImage(
controller: controller2,
image: NetworkImage("http://img.mp.itc.cn/upload/20161107/5cad975eee9e4b45ae9d3c1238ccf91e.jpg"),
),
Text("内存"),
GifImage(
controller: controller4,
image: MemoryImage(base64Decode(base64_url)),
5 years ago
)
],
),
Column(
children: <Widget>[
Row(
children: <Widget>[
RaisedButton(
child: Text("无限循环"),
onPressed: (){
controller3.repeat(min: 0,max: 25,period: Duration(milliseconds: 500));
},
),
RaisedButton(
child: Text("暂停"),
onPressed: (){
controller3.stop();
},
),
RaisedButton(
child: Text("播放到末尾一次"),
onPressed: (){
controller3.animateTo(52,duration: Duration(milliseconds: 1000));
},
)
],
),
Slider(
onChanged: (v){
controller3.value = v;
setState(() {
});
},
max: 53,
min: 0,
value: controller3.value,
),
GifImage(
controller: controller3,
image: AssetImage("images/animate.gif"),
),
],
)
5 years ago
],
),
),);
}
}