Created
June 4, 2019 03:10
-
-
Save Andrious/086a0dc2f778d148a12a5511b98a88eb to your computer and use it in GitHub Desktop.
Demonstrating much of the Scaffold's Named Parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/foundation.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/gestures.dart' show DragStartBehavior; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatefulWidget { | |
MyApp({Key key}) : super(key: key); | |
State createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin { | |
TabController controller; | |
@override | |
void initState() { | |
super.initState(); | |
controller = TabController(length: 3, vsync: this); | |
} | |
int _count = 0; | |
int _selectedIndex = 0; | |
@override | |
Widget build(BuildContext context) { | |
final title = 'Floating App Bar'; | |
final ThemeData theme = Theme.of(context); | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
title: title, | |
home: Scaffold( | |
appBar: AppBar( | |
leading: IconButton( | |
icon: Icon(Icons.home), | |
tooltip: 'Click to Home Screen', | |
onPressed: () {}), | |
automaticallyImplyLeading: true, | |
title: Text('My Fancy Dress'), | |
actions: <Widget>[ | |
IconButton( | |
icon: Icon(Icons.playlist_play), | |
tooltip: 'Air it', | |
onPressed: () {}, | |
), | |
IconButton( | |
icon: Icon(Icons.playlist_add), | |
tooltip: 'Restitch it', | |
onPressed: () {}, | |
), | |
IconButton( | |
icon: Icon(Icons.playlist_add_check), | |
tooltip: 'Repair it', | |
onPressed: () {}, | |
), | |
], | |
// flexibleSpace: Image.network( | |
// "https://images.pexels.com/photos/531880/pexels-photo-531880.jpeg?auto=compress&cs=tinysrgb&h=350", | |
// fit: BoxFit.cover, | |
// ), | |
bottom: TabBar( | |
tabs: [ | |
Tab(text: 'Tab 1'), | |
Tab(text: 'Tab 2'), | |
Tab(text: 'Tab 3'), | |
], | |
controller: controller, | |
), | |
elevation: 16, | |
backgroundColor: theme.primaryColor, | |
brightness: theme.primaryColorBrightness, | |
iconTheme: theme.primaryIconTheme, | |
actionsIconTheme: theme.appBarTheme.actionsIconTheme, | |
textTheme: theme.textTheme, | |
primary: true, | |
shape: StadiumBorder(), | |
centerTitle: true, | |
toolbarOpacity: 1.0, | |
bottomOpacity: 1.0, | |
), | |
body: Container( | |
decoration: | |
BoxDecoration(border: Border.all(width: 10, color: Colors.red)), | |
child: TabBarView( | |
controller: controller, | |
children: <Widget>[ | |
Center( | |
child: Text('You have pressed the button $_count times.'), | |
), | |
Text("Content for Tab 2"), | |
Text("Content for Tab 3"), | |
], | |
)), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () => setState(() { | |
_count++; | |
}), | |
tooltip: 'Increment Counter', | |
child: Icon(Icons.add), | |
), | |
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat, | |
persistentFooterButtons: <Widget>[ | |
IconButton(icon: Icon(Icons.insert_emoticon),onPressed: () {}), | |
IconButton(icon: Icon(Icons.mood),onPressed: () {}), | |
IconButton(icon: Icon(Icons.mood_bad),onPressed: () {}), | |
IconButton(icon: Icon(Icons.sentiment_dissatisfied),onPressed: () {}), | |
IconButton(icon: Icon(Icons.sentiment_neutral),onPressed: () {}), | |
IconButton(icon: Icon(Icons.sentiment_satisfied),onPressed: () {}), | |
IconButton(icon: Icon(Icons.sentiment_very_dissatisfied),onPressed: () {}), | |
], | |
drawer: _drawer, | |
endDrawer: _drawer, | |
bottomNavigationBar: BottomNavigationBar( | |
items: const <BottomNavigationBarItem>[ | |
BottomNavigationBarItem( | |
icon: Icon(Icons.home), | |
title: Text('Home'), | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.business), | |
title: Text('Business'), | |
), | |
BottomNavigationBarItem( | |
icon: Icon(Icons.school), | |
title: Text('School'), | |
), | |
], | |
currentIndex: _selectedIndex, | |
selectedItemColor: Colors.amber[800], | |
onTap: (int index) { | |
setState(() { | |
_selectedIndex = index; | |
}); | |
}, | |
), | |
bottomSheet: Container( | |
decoration: | |
BoxDecoration(border: Border.all(width: 1, color: Colors.red)), | |
child: Center(child: Text('bottomSheet')), | |
height: 30.0, | |
), | |
backgroundColor: Color(0xFFFF80AB), | |
resizeToAvoidBottomInset: false, | |
drawerDragStartBehavior: DragStartBehavior.down, | |
), | |
); | |
} | |
Widget get _drawer => Drawer( | |
// Add a ListView to the drawer. This ensures the user can scroll | |
// through the options in the Drawer if there isn't enough vertical | |
// space to fit everything. | |
child: ListView( | |
// Important: Remove any padding from the ListView. | |
padding: EdgeInsets.zero, | |
children: <Widget>[ | |
DrawerHeader( | |
child: Text('Drawer Header'), | |
decoration: BoxDecoration( | |
color: Colors.blue, | |
), | |
), | |
ListTile( | |
title: Text('Item 1'), | |
onTap: () { | |
// Update the state of the app | |
// ... | |
// Then close the drawer | |
Navigator.pop(context); | |
}, | |
), | |
ListTile( | |
title: Text('Item 2'), | |
onTap: () { | |
// Update the state of the app | |
// ... | |
// Then close the drawer | |
Navigator.pop(context); | |
}, | |
), | |
], | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment