diff --git a/example/miniplayer_with_bottomnav/lib/main.dart b/example/miniplayer_with_bottomnav/lib/main.dart new file mode 100644 index 0000000..6c996d7 --- /dev/null +++ b/example/miniplayer_with_bottomnav/lib/main.dart @@ -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 { + @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: [ + 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')), + ); + } +} \ No newline at end of file