route_ani_observer 0.0.1 route_ani_observer: ^0.0.1 copied to clipboard
A new Flutter package project.
import 'package:flutter/material.dart';
import 'package:route_ani_observer/route_ani_observer.dart';
void main() => runApp(
RouteAniObserverProvider(
child: App()
)
);
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'routeAniObserve',
home: Home(),
routes: {
'home': (_) => Home(),
'test1': (_) => Test1(),
'test2': (_) => Test2()
},
);
}
}
class Home extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return HomeState();
}
}
class HomeState extends State<Home> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
color: Colors.red,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Text('返回',
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none
)
),
onPressed: () {
Navigator.of(context).pop();
},
),
Text('home',
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none
)
),
RaisedButton(
onPressed: () {
Navigator.of(context).pushNamed('test1');
},
child: Text('test1',
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none
)
),
),
RaisedButton(
onPressed: () {
Navigator.of(context).pushNamed('test2');
},
child: Text('test2',
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none
)
),
),
],
),
);
}
}
class Test1 extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return Test1State();
}
}
class Test1State extends State<Test1> with RouteAniCompleteMixin, RouteAniListenerMixin {
@override
onRouteAniComplete() {
print('routeAniCompleteHandler- test1');
}
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
color: Colors.blue,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Text('返回',
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none
)
),
onPressed: () {
Navigator.of(context).pop();
},
),
Text('test1', style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none
)),
RaisedButton(
onPressed: () {
Navigator.of(context).pushNamed('home');
},
child: Text('返回到home',
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none
)
),
),
RaisedButton(
onPressed: () {
Navigator.of(context).pushNamed('test2');
},
child: Text('到test2',
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none
)
),
),
],
),
);
}
}
class Test2 extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return Test2State();
}
}
class Test2State extends State<Test2> with RouteAniCompleteMixin, RouteAniListenerMixin {
@override
onRouteAniComplete() {
print('routeAniCompleteHandler- test2');
}
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
color: Colors.green,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Text('返回',
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none
)
),
onPressed: () {
Navigator.of(context).pop();
},
),
Text('test2',
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none
)),
RaisedButton(
onPressed: () {
Navigator.of(context).pushNamed('home');
},
child: Text('返回到home', style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none
)),
),
RaisedButton(
onPressed: () {
Navigator.of(context).pushNamed('test1');
},
child: Text('到test1', style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none
)),
),
],
),
);
}
}