Created
March 31, 2021 07:33
-
-
Save cankush625/6ee34c70d455e34900aa385b5a2ea94e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter/services.dart'; | |
import 'package:rive/rive.dart'; | |
class Search extends StatefulWidget { | |
@override | |
_SearchState createState() => _SearchState(); | |
} | |
class _SearchState extends State<Search> { | |
final riveFileName = 'assets/search.riv'; | |
Artboard _artboard; | |
@override | |
void initState() { | |
_loadRiveFile(); | |
super.initState(); | |
} | |
// loads a Rive file | |
void _loadRiveFile() async { | |
final bytes = await rootBundle.load(riveFileName); | |
final file = RiveFile(); | |
if (file.import(bytes)) { | |
// Select an animation by its name | |
setState(() => _artboard = file.mainArtboard | |
..addController( | |
SimpleAnimation('search_animation'), | |
)); | |
} | |
} | |
@override | |
Widget build(BuildContext context) { | |
var screensize = MediaQuery.of(context).size; | |
return Scaffold( | |
body: SafeArea( | |
child: Column( | |
children: [ | |
Container( | |
height: 400, | |
width: 350, | |
child: _artboard != null | |
? Rive( | |
artboard: _artboard, | |
fit: BoxFit.cover, | |
) | |
: Container(), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment