I am using drawer of my flutter app .I register first then redirect to Home Page .I have used drawer in my Home Page . I added some some menu on drawer then redirect to some new activity . I have added WillPopScope in Home page to tigged android back press .But problem is when i clicked back button from other activity but home activity WillPopScope calling.
This is home page
return WillPopScope(
onWillPop: (){
exit(0);
},
child: MaterialApp(
home: Scaffold(
drawer: StudentDrawer(
number: widget.number,
),
appBar: AppBar(
actions: <Widget>[
InkWell(
child: new Icon(
Icons.notifications,
color: Colors.white,
),
onTap: () {},
),
InkWell(
child: Icon(
Icons.more_vert,
color: Colors.white,
),
onTap: () {
_scaffoldKey.currentState.openDrawer();
},
),
],
title: Text(
"Home",
style: new TextStyle(
color: Colors.white,
letterSpacing: 1.0,
fontSize: 20,
fontStyle: FontStyle.normal),
),
),
body: SingleChildScrollView(
child: new Column(
children: <Widget>[
//top(),
/*SizedBox(
height: 7,
),*/
bottom()
],
),
),
),
),
);
This is drawer page
return Drawer(
child: Column(
children: <Widget>[ header(), Expanded(child: list(context))],
),
);
Widget list(BuildContext context) => new ListView(
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: <Widget>[
ListTile(
onTap: (){
Navigator.pop(context);
Navigator.of(context).push(new MaterialPageRoute(builder: (context)=>Profile(number:widget.number)));
},
leading: new Icon(
Icons.perm_identity,
color: Colors.green,
),
title: Text(
"Profile",
style: TextStyle(color: Colors.green),
),
),
And This is my profile activity
return WillPopScope(
onWillPop:(){
print(" It's not calling .....");
Navigator.pop(context);
}
,
child: MaterialApp(
home: Scaffold(
appBar: AppBar(
leading: InkWell(
onTap: (){
Navigator.pop(context);
},
child:Icon(Icons.arrow_back,color: Colors.white,),
),
title: Text("Profile"),
),
Basically everything fine but problem is when i click back button from profile activity its calling onWillPop of Home activity ..
Related
I am facing a problem with my custom app bar. I would like it to have a drawer but it doesn't work. I just don't know how to make it being able to open.
It is a custom app bar widget named Pasek (which stands for top bar in my language).
It has a logo picture which on click moves you to the first page of the app.
Next to it there is humburger menu with a drawer but I do not know why it doesn't work. I click on it and nothing happens.
Any ideas?
class Pasek extends StatelessWidget with PreferredSizeWidget {
#override
Size get preferredSize => Size.fromHeight(50.0);
const Pasek({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return AppBar(
actions: <Widget>[
Padding(
padding: EdgeInsets.only(right: 35.0),
child: ElevatedButton(
child: Icon(Icons.menu, color: Colors.white),
onPressed: () {
Scaffold(
endDrawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: const <Widget>[
DrawerHeader(
decoration: BoxDecoration(
color: Colors.black,
),
child: Text(
'Menu',
style: TextStyle(
color: Colors.pink,
fontSize: 24,
),
),
),
ListTile(
leading: Icon(Icons.message),
title: Text('Messages'),
),
ListTile(
leading: Icon(Icons.account_circle),
title: Text('Profile'),
),
ListTile(
leading: Icon(Icons.settings),
title: Text('Settings'),
),
],
),
),
);
},
)),
],
backgroundColor: Colors.black,
title: GestureDetector(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => FirstPage(),
),
);
}, // Image tapped
child: Image.asset(
'images/logo.png',
fit: BoxFit.scaleDown,
height: 30,
width: 200,
),
));
}
}
I am using Default Sidebar but getting error while scroll
'The $controllerForError is currently attached to more than one '
'ScrollPosition.',
here is Sidebar Widget
#override
Widget build(BuildContext context) {
return ListView(
children: <Widget>[
DrawerHeader(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/bgimage.jpg"),
fit: BoxFit.cover),
color: Colors.blue,
),
child: Center(
child: Column(
children: [
Text(
'${store.user['name']}',
style: TextStyle(color: Colors.white, fontSize: 25),
),
Lottie.asset(
'assets/lottie/coin.json',
width: 50,
height: 50,
),
Text(
'${store.user['wallet']}',
style: TextStyle(color: Colors.white, fontSize: 20),
),
],
)),
),
ListTile(
leading: Icon(Icons.home),
title: Text('Home'),
onTap: () {
Navigator.popAndPushNamed(context, '/home');
},
),
ListTile(
leading: Icon(Icons.assessment_outlined),
title: Text('Loss/Profit'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
leading: Icon(Icons.calendar_today),
title: Text('Results'),
onTap: () {
Navigator.popAndPushNamed(context, '/result');
},
),
ListTile(
leading: Icon(Icons.supervised_user_circle),
title: Text('Referrals'),
onTap: () {
Navigator.pop(context);
},
),
],
);
}
}
Using in homepage
drawer: Drawer(
child: Sidebar(),
),
where is scroll position is using multiple
by default drawer is already scrollable. i think the cause of not being able to scroll is not in the drawer
Hi I'm trying to add a drawer to my scaffold with the help of https://flutter.dev/docs/cookbook/design/drawer
And so far I'm getting multiple errors when I try to use it (and found 2, I don't know if there is more).
Code:
#override
Widget build(BuildContext context) {
return Scaffold(
drawer: Drawer(
child: Row(
children: <Widget>[
IconButton(icon: Icon(Icons.add), onPressed: () {}),
ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text(
"What's up?",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 30),
),
decoration: BoxDecoration(color: Color(0xff171719)),
),
ListTile(
title: Text(
"Change Theme",
style: TextStyle(fontSize: 24),
),
// ignore: todo
onTap: () {}, //TODO add dark mode
),
ListTile(
title: Text(
"Sign Out",
style: TextStyle(fontSize: 24),
),
onTap: () {
AuthMethods().signOut().then(
(s) {
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => SignIn()));
Navigator.pop(context);
},
);
// ignore: todo
}, //TODO sign out
),
],
),
],
),
),
Exception caught by gesture:
Exception caught by rendering library:
I couldn’t reproduce it on my end, but this usually means that there’s a widget whose viewport doesn’t have the dimensions established.
This generally happens when you add a ListView directly to a Row or Column. Y would suggest wrapping your ListView with an Expanded widget (or a Container).
You should put your ListView inside a Widget that will constraint the ListView vertically, such as Expanded:
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
void main() {
runApp(
MaterialApp(
title: 'Flutter Demo',
home: Scaffold(body: MyWidget()),
),
);
}
class MyWidget extends HookWidget {
#override
Widget build(BuildContext context) {
final _drawerKey = useState<GlobalKey<ScaffoldState>>(GlobalKey());
return Scaffold(
key: _drawerKey.value,
drawer: Drawer(
child: Row(
children: <Widget>[
IconButton(icon: Icon(Icons.add), onPressed: () {}),
Expanded(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text(
"What's up?",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 30),
),
decoration: BoxDecoration(color: Color(0xff171719)),
),
ListTile(
title: Text(
"Change Theme",
style: TextStyle(fontSize: 24),
),
// ignore: todo
onTap: () {}, //TODO add dark mode
),
ListTile(
title: Text(
"Sign Out",
style: TextStyle(fontSize: 24),
),
onTap: () {
print('SIGN OUT');
}, //TODO sign out
),
],
),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => _drawerKey.value.currentState.openDrawer(),
),
);
}
}
Solution 1: Set ListView inside Expanded
Solution 2: ListView with the attribute: shrinkWrap: true,
everyone
I'm encountering a problem while using Flutter.
Basically when i open my CustomDrawer widget, not always but quite frequently, the keyboard pops out in an unwanted way.
I don't get why it does it... maybe because it re-runs the build method or something i don't know. Down below you can find the code.
Every little bit of information is well appreciated.
Thanks everyone.
Here's the Screen.dart
...
build(context) {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
iconTheme: IconThemeData(color: Colors.white),
backgroundColor: Colors.transparent,
elevation: 0,
),
drawer: CustomDrawer(),
...
And the custom_drawer_widget.dart
...
#override
Widget build(BuildContext context) {
return Drawer(
child: Column(
children: [
Stack(
children: [
Container(
padding: EdgeInsets.all(20),
child: Text(
"Hi, $username",
style: TextStyle(
fontSize: 22,
),
),
alignment: Alignment.bottomLeft,
color: Colors.yellow,
height: 300,
),
],
),
Container(
height: 60.0 * 6,
child: Column(
children: [
Container(
height: 60,
child: FlatButton(
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
highlightColor: Colors.grey[350],
color: Colors.transparent,
onPressed: () {},
child: Row(
children: [
Icon(
Icons.home,
color: Colors.grey[600],
),
SizedBox(width: 30),
Text("Homepage"),
],
),
),
),
ListTile(
leading: Icon(Icons.book),
title: Text("Diary"),
onTap: () {}),
ListTile(
leading: Icon(Icons.chat),
title: Text("Chat"),
onTap: () {}),
ListTile(
leading: Icon(Icons.credit_card),
title: Text("Credit Card"),
onTap: () {}),
ListTile(
leading: Icon(Icons.exit_to_app),
title: Text("Sign Out"),
onTap: () async {
await FirebaseAuth.instance.signOut();
}),
ListTile(
leading: Icon(Icons.settings),
title: Text("Settings"),
onTap: () {}),
],
),
),
Expanded(
child: Container(
padding: EdgeInsets.all(22),
alignment: Alignment.bottomLeft,
child: Row(
children: [
Text("Version 0.1"),
],
),
),
)
],
),
);
}
...
I don't see exactly where you dismiss the keyboard, but I was having the same issue after dismissing the keyboard after a form submit. This fixed my issue.
See this answer here:
https://github.com/flutter/flutter/issues/54277
Where instead of:
onTap: () {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
},
The code should be:
onTap: () {
final FocusScopeNode currentScope = FocusScope.of(context);
if (!currentScope.hasPrimaryFocus && currentScope.hasFocus) {
FocusManager.instance.primaryFocus.unfocus();
}
},
My MaterialApp started to behave strange today. The TournamnetScreen is created twice when I click on the admin tab.
What could possible cause this? I upgraded flutter yesterday. (stable channel)
#override
Widget build(BuildContext context) {
debugPrint("Starting Chess Champion");
return MaterialApp(
theme: new ThemeData(
primarySwatch: Colors.blue,
scaffoldBackgroundColor: Colors.grey
),
home: DefaultTabController(
length: 5,
child:
Scaffold(
appBar: AppBar(
title: Text('Chess Champion', style: new TextStyle(fontWeight: FontWeight.normal, fontSize: 30.0)),
bottom: TabBar(
tabs: [
Tab(icon: Icon(Icons.home)),
Tab(icon: Icon(AntDesign.table)),
Tab(icon: Icon(Octicons.versions)),
Tab(icon: Icon(MaterialCommunityIcons.podium)),
Tab(icon: Icon(Octicons.tools)),
],
),
),
body: TabBarView(
children: [
HomeScreen(title: 'Home',),
DataTableScreen(),
ChangelogScreen(),
TeamTournamentScreen(),
AdminScreen(),
],
),
),
),
);
}
Admin widget here ..
class AdminScreen extends StatelessWidget {
final _scaffoldKey = GlobalKey<ScaffoldState>();
#override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(title: Text('Admin')),
body: Builder(builder: (BuildContext context) {
return Column(
children: <Widget>[
RaisedButton(
onPressed: _createTour2,
child: new Text('Create a tournament2'),
),
RaisedButton(
onPressed: _readTour,
child: new Text('Read a tournament'),
),
RaisedButton(
onPressed: _deleteTour,
child: new Text('Delete a tournament'),
),
RaisedButton(
onPressed: _setTourLevel,
child: new Text('Set level in all Tournaments'),
),
RaisedButton(
onPressed: _listTours,
child: new Text('List Tournaments'),
),
RaisedButton(
onPressed: _listTour2s,
child: new Text('List Tournament2s '),
),
RaisedButton(
onPressed: _deleteDuplicatedTours,
child: new Text('Delete Duplicated Tournaments'),
),
RaisedButton(
onPressed: _scrapeAllsvenskan,
child: new Text('Scrape Allsvenskan'),
),
RaisedButton(
onPressed: _listClubs,
child: new Text('List Clubs'),
),
RaisedButton(
onPressed: _updateTour,
child: new Text('Update a Tournament'),
),
RaisedButton(
onPressed: _deleteDuplicatClubs,
child: new Text('Remove duplicate Clubs'),
),
RaisedButton(
onPressed: _dbCounts,
child: new Text('Database Counts'),
),
],
);
}),
);
}
This turned out to be to the fact that I accidentically created two MaterialApp's.