mirror of
https://github.com/xvrh/lottie-flutter.git
synced 2025-08-06 16:39:36 +08:00

Update documentation to use `AssetLottie(...).load()` instead of `LottieComposition.fromByteData(...)` Resolves https://github.com/xvrh/lottie-flutter/issues/215
53 lines
1.1 KiB
Dart
53 lines
1.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:lottie/lottie.dart';
|
|
|
|
void main() => runApp(const MyApp());
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const MaterialApp(
|
|
home: Scaffold(
|
|
body: MyWidget(),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
//--- example
|
|
class MyWidget extends StatefulWidget {
|
|
const MyWidget({super.key});
|
|
|
|
@override
|
|
State<MyWidget> createState() => _MyWidgetState();
|
|
}
|
|
|
|
class _MyWidgetState extends State<MyWidget> {
|
|
late final Future<LottieComposition> _composition;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
_composition = AssetLottie('assets/LottieLogo1.json').load();
|
|
}
|
|
|
|
@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 const Center(child: CircularProgressIndicator());
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|
|
//---
|