forked from mark922/flutter_lottie
/
main.dart
130 lines (120 loc) · 3.88 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:lokstory_flutter_lottie/lokstory_flutter_lottie.dart';
import 'page_dragger.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
LottieController controller;
LottieController controller2;
StreamController<double> newProgressStream;
_MyAppState() {
newProgressStream = new StreamController<double>();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: PageDragger(
stream: this.newProgressStream,
child: Scaffold(
appBar: AppBar(
title: const Text('Lottie'),
),
body: Center(
child: Column(
children: <Widget>[
SizedBox(
width: 150,
height: 150,
child: LottieView.fromURL(
url: "https://raw.githubusercontent.com/airbnb/lottie-ios/master/Example/Tests/Watermelon.json",
autoPlay: true,
loop: true,
reverse: true,
onViewCreated: onViewCreated,
)
),
FlatButton(
child: Text("Play"),
onPressed: () {
controller.play();
},
),
FlatButton(
child: Text("Stop"),
onPressed: () {
controller.stop();
},
),
FlatButton(
child: Text("Pause"),
onPressed: () {
controller.pause();
},
),
FlatButton(
child: Text("Resume"),
onPressed: () {
controller.resume();
},
),
Text("From File"),
Container(
child: SizedBox(
width: 150,
height: 150,
child: LottieView.fromFile(
filePath: "animations/newAnimation.json",
autoPlay: true,
loop: true,
reverse: true,
onViewCreated: onViewCreatedFile,
),
),
),
FlatButton(
child: Text("Change Color"),
onPressed: () {
// Set Color of KeyPath
this.controller2.setValue(
value: LOTColorValue.fromColor(
color: Color.fromRGBO(0, 0, 255, 1)
),
keyPath: "body Konturen.Gruppe 1.Fläche 1"
);
// Set Opacity of KeyPath
this.controller2.setValue(
value: LOTOpacityValue(opacity: 0.1),
keyPath: "body Konturen.Gruppe 1.Fläche 1"
);
},
),
Text("Drag anywhere to change animation progress"),
],
),
),
),
),
);
}
void onViewCreated(LottieController controller) {
this.controller = controller;
// Listen for when the playback completes
this.controller.onPlayFinished.listen((bool animationFinished) {
print("Playback complete. Was Animation Finished? " + animationFinished.toString());
});
}
void onViewCreatedFile(LottieController controller) {
this.controller2 = controller;
newProgressStream.stream.listen((double progress) {
this.controller2.setAnimationProgress(progress);
});
}
void dispose() {
super.dispose();
newProgressStream.close();
}
}