Add example
This commit is contained in:
parent
0fca3c3ae4
commit
2c41644d05
|
@ -0,0 +1,137 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:miniplayer/miniplayer.dart';
|
||||
|
||||
void main() => runApp(MyApp());
|
||||
|
||||
final _navigatorKey = GlobalKey();
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
primaryColor: Color(0xFFFAFAFA),
|
||||
),
|
||||
home: MyHomePage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
@override
|
||||
_MyHomePageState createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
final NavigatorState navigator = _navigatorKey.currentState;
|
||||
if (!navigator.canPop()) return true;
|
||||
navigator.pop();
|
||||
|
||||
return false;
|
||||
},
|
||||
child: Scaffold(
|
||||
body: Stack(
|
||||
children: <Widget>[
|
||||
Navigator(
|
||||
key: _navigatorKey,
|
||||
onGenerateRoute: (RouteSettings settings) {
|
||||
return MaterialPageRoute(
|
||||
settings: settings,
|
||||
builder: (BuildContext context) => FirstScreen(),
|
||||
);
|
||||
},
|
||||
),
|
||||
Miniplayer(
|
||||
minHeight: 70,
|
||||
maxHeight: 370,
|
||||
builder: (height, percentage) {
|
||||
return Center(
|
||||
child: Text('$height, $percentage'),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
currentIndex: 0,
|
||||
fixedColor: Colors.green,
|
||||
items: [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.home),
|
||||
title: Text('Home'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.mail),
|
||||
title: Text('Messages'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.person), title: Text('Profile'))
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class FirstScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text('Demo: FirstScreen')),
|
||||
body: Container(
|
||||
constraints: BoxConstraints.expand(),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
RaisedButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => SecondScreen()),
|
||||
);
|
||||
},
|
||||
child: const Text('Open SecondScreen',
|
||||
style: TextStyle(fontSize: 20)),
|
||||
),
|
||||
RaisedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
MaterialPageRoute(builder: (context) => ThirdScreen()),
|
||||
);
|
||||
},
|
||||
child: const Text('Open ThirdScreen with root Navigator',
|
||||
style: TextStyle(fontSize: 20)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SecondScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text('Demo: SecondScreen')),
|
||||
body: Center(child: Text('SecondScreen')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ThirdScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text('Demo: ThirdScreen')),
|
||||
body: Center(child: Text('ThirdScreen')),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue