Say I want to build a StatefulWidget named MySlideWidget
that provides a public instance method: animate()
.
When I press a button on parent of MySlideWidget
, then I can call MySlideWidget
's animate()
method to trigger an internal SlideTransition
of MySlideWidget
.
The usage would look like this:
class MySlideWidgetDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
MySlideWidget mySlideWidget = new MySlideWidget();
return new Scaffold(
body: mySlideWidget,
floatingActionButton: new FloatingActionButton(
onPressed: () {
mySlideWidget.animate();
},
tooltip: 'Start',
child: new Icon(Icons.add),
));
}
}
What I wondering is how to encapsulate the implementations of AnimationController
and _controller.forward()
inside MySlideWidget
, so user of MySlideWidget
can simply call animate()
.
Is this possible? Or what is the idea way to do encapsulation in Flutter?