mirror of
https://github.com/xvrh/lottie-flutter.git
synced 2025-08-06 16:39:36 +08:00
56 lines
1.3 KiB
Dart
56 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:lottie/lottie.dart';
|
|
|
|
void main() => runApp(MyApp());
|
|
|
|
class MyApp extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
home: Scaffold(
|
|
body: MyWidget(),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
//--- example
|
|
class MyWidget extends StatefulWidget {
|
|
@override
|
|
_MyWidgetState createState() => _MyWidgetState();
|
|
}
|
|
|
|
class _MyWidgetState extends State<MyWidget> {
|
|
Future<LottieComposition> _composition;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
_composition = _loadComposition();
|
|
}
|
|
|
|
Future<LottieComposition> _loadComposition() async {
|
|
var assetData = await rootBundle.load('assets/LottieLogo1.json');
|
|
return await LottieComposition.fromByteData(assetData);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FutureBuilder<LottieComposition>(
|
|
future: _composition,
|
|
builder: (context, snapshot) {
|
|
var composition = snapshot.data;
|
|
if (composition != null) {
|
|
return Lottie(composition: composition);
|
|
} else {
|
|
return Center(child: CircularProgressIndicator());
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|
|
//---
|