Skip to content

Instantly share code, notes, and snippets.

@cankush625
Created March 31, 2021 07:33
Show Gist options
  • Save cankush625/6ee34c70d455e34900aa385b5a2ea94e to your computer and use it in GitHub Desktop.
Save cankush625/6ee34c70d455e34900aa385b5a2ea94e to your computer and use it in GitHub Desktop.
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