SingleTickerProviderStateMixin and custom mixin - flutter

I'm a bit of a newb with Flutter and Dart, and Google couldn't help me with this question.
Say I have this:
class _MapPageState extends BaseState<MapPage> with SingleTickerProviderStateMixin
I want to add another mixin (BasePage) on top of this that contains a reusable appbar, drawer, etc. The layout is described in this article.
I know this is not possible, and my IDE throws an error that tells me to integrate them, but I do not know how. Is there a solution? I need SingleTickerProviderStateMixin because it is required by an AnimationController I am using.
Here is the custom mixin code, if needed:
abstract class Base extends StatefulWidget {
Base({Key key}) : super(key: key);
}
abstract class BaseState<Page extends Base> extends State<Page> {
String screenName();
}
mixin BasePage<Page extends Base> on BaseState<Page> {
MapFunctions functions = MapFunctions();
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Guidey'),
backgroundColor: Colors.deepOrangeAccent,
centerTitle: true,
),
drawer: Theme(
data: Theme.of(context).copyWith(
canvasColor: Colors.black.withOpacity(0.5)
),
child: Drawer(
child: ListView(
padding: EdgeInsets.fromLTRB(40.0, 10.0, 40.0, 10.0),
children: <Widget>[
DrawerHeader(
child: Padding(
padding: EdgeInsets.fromLTRB(0, 35, 0, 0),
child: Text('Navigation', textAlign: TextAlign.center, style: TextStyle(fontSize: 20, color: Colors.white))
)
),
ListTile(
title: Text('Profile', style: TextStyle(color: Colors.white)),
trailing: Icon(Icons.account_circle, color: Colors.white70),
onTap: (){
Navigator.of(context).pop();
},
),
ListTile(
title: Text('Map', style: TextStyle(color: Colors.white)),
trailing: Icon(Icons.drive_eta, color: Colors.white70),
onTap: (){
Navigator.of(context).pop();
},
),
ListTile(
title: Text('My Location', style: TextStyle(color: Colors.white)),
trailing: Icon(Icons.store, color: Colors.white70),
onTap: (){
},
)
],
)
),
),
);
}
Widget body();
}

It turns out I was thinking too big, combining mixins can be done with a simple comma.
... with SingleTickProviderMixin, BasePageMixin

Related

Multiple ExpansionTile with multiple ListTile, how to do a second one

This question might sound dumb, but I am trying to make a list of Expandable list items which in turn have a list of items inside. I have come this far but I am unable to make it a show a second one WITHOUT USING INDEX.
import 'package:flutter/material.dart';
class ExerciseScreen extends StatefulWidget {
const ExerciseScreen({Key? key}) : super(key: key);
#override
State<ExerciseScreen> createState() => _ExerciseScreenState();
}
class _ExerciseScreenState extends State<ExerciseScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Table of Contents CEFR'),
),
body: ListView(
children: const [
ExpansionTile(
leading: Padding(
padding: EdgeInsets.all(8.0),
child: CircleAvatar(
backgroundColor: Color.fromARGB(255, 0, 182, 91),
child: Text(
'A1',
style: TextStyle(fontSize: 15, color: Colors.white),
),
),
),
title: Text(
'To be: is, am, are',
style: TextStyle(fontSize: 21, color: Colors.black),
),
children: [
ListTile(
leading: CircleAvatar(
child: Text('A1'),
),
title: Text('Affirmative ideas'),
subtitle: Text('Singular and plural subjects'),
),
ListTile(
leading: CircleAvatar(
child: Text('A1'),
),
title: Text('Are: plural verb'),
subtitle: Text('Positive ideas using plural subjects'),
),
ListTile(
leading: CircleAvatar(
child: Text('A1'),
),
title: Text('Is : singular verb'),
subtitle: Text('Positive ideas using singular subjects'),
),
ListTile(
leading: CircleAvatar(
child: Text('A1'),
),
title: Text('Questions'),
subtitle: Text('Interrogative ideas - subject/verb/switch '),
),
ListTile(
leading: CircleAvatar(
child: Text('A1'),
),
title: Text('Questions'),
subtitle: Text('Closed questions (yes/no)'),
),
],
),
],
),
);
}
}
What is the problem with just adding a second ExpansionTile to your list? Like so:
import 'package:flutter/material.dart';
class ExerciseScreen extends StatefulWidget {
const ExerciseScreen({Key? key}) : super(key: key);
#override
State<ExerciseScreen> createState() => _ExerciseScreenState();
}
class _ExerciseScreenState extends State<ExerciseScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Table of Contents CEFR'),
),
body: ListView(
children: const [
ExpansionTile(...),
ExpansionTile(...),
],
),
);
}
}
On my side it shows both ExpansionTiles correctly:

What do I need to do to link to another file with my button widgets?

I am still learning to code. How do I store all my button widgets in another file and import it into my main file? Here is the code:
class _testState extends State<test> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue[900],
appBar: AppBar(
title: Text('test'),
backgroundColor: Colors.red[900],
),
body: GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
),
children: [
//buttons
],
),
);
}
}
How can I take the code below and put it in another file and then link it to the file above by the buttons comment?
Padding(
padding: const EdgeInsets.fromLTRB(0.0, 9.0, 0.0, 0.0),
child: TextButton.icon(
onPressed: () => {},
icon: Column(
children: [
Icon(
Icons.add,
color: Colors.white,
size: 75,
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Text(
'Label',
style: TextStyle(
color: Colors.white,
),
),
),
],
),
label: Text(
'', //'Label',
style: TextStyle(
color: Colors.white,
),
),
),
),
-First, create a new file, name it jeff.dart.
-Second, type this in the new file: stless . Press Enter, Flutter will automatically make a new StatelessWidget for you. Change the class name to JeffButton. Now, it look like this :
class JeffButton extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
);
}
}
Copy and paste the button's code , replace the Container() .Congratulations! You had the JeffButton! Now you can use it everywhere:
class JeffButton extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.fromLTRB(0.0, 9.0, 0.0, 0.0),
child: TextButton.icon(
onPressed: () => {},
icon: Column(
children: [
Icon(
Icons.add,
color: Colors.white,
size: 75,
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Text(
'Label',
style: TextStyle(
color: Colors.white,
),
),
),
],
),
label: Text(
'', //'Label',
style: TextStyle(
color: Colors.white,
),
),
),
);
}
}
Now just add it to where you need it ;) :
children: [
//buttons
JeffButton(),
],
Remember to import the jeff.dart file to where you use it, you can do it easily by move the cursor to JeffButton(), show quick fixes, choose Import: .... (which is the first options). This is how to show quick fixes if you didn't know: https://flutter.dev/docs/development/tools/flutter-fix

I am getting two appBar in flutter app. I am trying to add Drawer widget and TabBar widget in flutter app

main.dart
import 'package:flutter/material.dart';
import 'package:stray_animal_emergencyrescue/signUpPage.dart';
import './commons/commonWidgets.dart';
import 'package:stray_animal_emergencyrescue/loggedIn.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
//title: 'Flutter login UI',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
//String showPasswordText = "Show Password";
bool obscurePasswordText = true;
#override
Widget build(BuildContext context) {
final passwordField = TextField(
obscureText: obscurePasswordText,
decoration: InputDecoration(
//contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
hintText: "Password",
//border: OutlineInputBorder(borderRadius: BorderRadius.circular(32.0)),
suffixIcon: IconButton(
icon: new Icon(Icons.remove_red_eye),
onPressed: () {
setState(() {
this.obscurePasswordText = !obscurePasswordText;
});
},
)),
);
final loginButon = Material(
//elevation: 5.0,
//borderRadius: BorderRadius.circular(30.0),
color: Colors.blue,
child: MaterialButton(
//minWidth: MediaQuery.of(context).size.width,
//padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {
//print(MediaQuery.of(context).size.width);
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => LogIn()),
);
},
child: Text('Login', textAlign: TextAlign.center),
),
);
final facebookContinueButton = Material(
//borderRadius: BorderRadius.circular(30.0),
color: Colors.blue,
child: MaterialButton(
//minWidth: MediaQuery.of(context).size.width,
//padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {
//print(MediaQuery.of(context).size.width);
},
child: Text('Facebook', textAlign: TextAlign.center),
),
);
final googleContinueButton = Material(
//borderRadius: BorderRadius.circular(30.0),
color: Colors.blue,
child: MaterialButton(
//minWidth: MediaQuery.of(context).size.width,
//padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {
//print(MediaQuery.of(context).size.width);
},
child: Text('Google ', textAlign: TextAlign.center),
),
);
final signUpButton = Material(
//borderRadius: BorderRadius.circular(30.0),
color: Colors.blue,
child: MaterialButton(
//minWidth: MediaQuery.of(context).size.width,
//padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => FormScreen()),
);
//print(MediaQuery.of(context).size.width);
},
child: Text('Sign Up ', textAlign: TextAlign.center),
),
);
return Scaffold(
appBar: AppBar(
title: Text("Animal Emergency App"),
),
body: Center(
child: Container(
//color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(36.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
//SizedBox(height: 45.0),
getTextFieldWidget(),
SizedBox(height: 15.0),
passwordField,
sizedBoxWidget,
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
facebookContinueButton,
SizedBox(width: 5),
googleContinueButton,
SizedBox(width: 5),
loginButon
],
),
/*loginButon,
signUpButton,*/
sizedBoxWidget,
const Divider(
color: Colors.black,
height: 20,
thickness: 1,
indent: 20,
endIndent: 0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
//crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
signUpButton
],
),
],
),
),
),
),
);
}
}
loggedIn.dart
import 'package:flutter/material.dart';
import './tabbarviews/emergencyresue/EmergencyHome.dart';
import './tabbarviews/animalcruelty/animalCrueltyHome.dart';
import './tabbarviews/bloodbank/bloodBankHome.dart';
class LogIn extends StatefulWidget {
#override
_LogInState createState() => _LogInState();
}
class _LogInState extends State<LogIn> {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static List<Widget> _widgetOptions = <Widget>[
EmergencyHome(),
AnimalCrueltyHome(),
BloodBankHome()
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First app bar appearing'),
actions: <Widget>[
GestureDetector(
onTap: () {},
child: CircleAvatar(
//child: Text("SC"),
backgroundImage: AssetImage('assets/images/760279.jpg'),
//backgroundImage: ,
),
),
IconButton(
icon: Icon(Icons.more_vert),
color: Colors.white,
onPressed: () {},
),
],
),
drawer: Drawer(
child: ListView(
children: <Widget>[
new ListTile(title: Text("Primary")),
MyListTile(
"Home",
false,
"Your customized News Feed about people you follow, ongoing rescues, nearby activities, adoptions etc.",
3,
Icons.home,
true,
() {}),
MyListTile(
"News & Media Coverage",
false,
"News about incidents which need immediate action, changing Laws",
3,
Icons.home,
false,
() {}),
MyListTile(
"Report",
true,
"Report cases with evidences anonymously",
3,
Icons.announcement,
false,
() {}),
MyListTile(
"Blood Bank",
true,
"Details to donate blood ",
3,
Icons.medical_services,
false,
() {}),
],
),
),
body: _widgetOptions[_selectedIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedIndex,
selectedItemColor: Colors.blue,
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.pets),
label: 'Emergency Rescue',
),
BottomNavigationBarItem(
icon: Icon(Icons.add_alert),
label: 'Report Cruelty',
),
BottomNavigationBarItem(
icon: Icon(Icons.medical_services),
label: 'Blood Bank',
),
/*BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'Safe Hands',
backgroundColor: Colors.blue),*/
],
onTap: _onItemTapped,
),
);
}
}
//Safe Hands
class MyListTile extends StatelessWidget {
final String title;
final bool isThreeLine;
final String subtitle;
final int maxLines;
final IconData icon;
final bool selected;
final Function onTap;
MyListTile(this.title, this.isThreeLine, this.subtitle, this.maxLines,
this.icon, this.selected, this.onTap);
#override
Widget build(BuildContext context) {
return ListTile(
title: Text(title),
isThreeLine: isThreeLine,
subtitle:
Text(subtitle, maxLines: maxLines, style: TextStyle(fontSize: 12)),
leading: Icon(icon),
selected: selected,
onTap: onTap);
}
}
EmergencyHome.dart
import 'package:flutter/material.dart';
import './finishedAnimalEmergencies.dart';
import './reportAnimalEmergency.dart';
import './ongoingAnimalEmergencies.dart';
class EmergencyHome extends StatefulWidget {
#override
_EmergencyHomeState createState() => _EmergencyHomeState();
}
class _EmergencyHomeState extends State<EmergencyHome> {
#override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: Text("Second appBar appearing"),
bottom: TabBar(
tabs: [
Tab(
//icon: Icon(Icons.more_vert),
text: "Report",
),
Tab(
text: "Ongoing",
),
Tab(
text: "Finished",
)
],
),
),
body: TabBarView(
children: [
ReportAnimalEmergency(),
OngoingAnimalEmergencies(),
FinishedAnimalEmergencies(),
],
),
)
);
}
}
The issue I am facing is two appBar, I tried removing appBar from loggedIn.dart but Drawer hamburger icon is not showing, and I cannot remove appBar from emergencyHome.dart as I wont be able to add Tab bar. What is viable solution for this? Please help how to Structure by app and routes to easily manage navigation within app
Remove the appbar from EmergencyHome.dart
this will remove the second app title. But there will be that shadow from the first app bar so put elvation:0
so, this will look like one appbar now your drawer will also work.
you can use flexibleSpace in EmergencyHome.dart
DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
flexibleSpace: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
TabBar(
tabs: [
Tab(
//icon: Icon(Icons.more_vert),
text: "Report",
),
Tab(
text: "Ongoing",
),
Tab(
text: "Finished",
)
],
)
],
),
),
body: TabBarView(
children: [
ReportAnimalEmergency(),
OngoingAnimalEmergencies(),
FinishedAnimalEmergencies(),
],
),
)
);
You don't want to make two appbar to get the drawer property. Use DefaultTabController then inside that you can use scaffold.so, you can have drawer: Drawer() inside that you can also get a appbar with it with TabBar as it's bottom.
This is most suitable for you according to your use case.
i will put the full code below so you can copy it.
void main() {
runApp(const TabBarDemo());
}
class TabBarDemo extends StatelessWidget {
const TabBarDemo({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
home: DefaultTabController(
length: 3,
child: Scaffold(
drawer: Drawer(),
appBar: AppBar(
bottom: const TabBar(
tabs: [
Tab(
text: "report",
),
Tab(text: "ongoing"),
Tab(text: "completed"),
],
),
title: const Text('Tabs Demo'),
),
body: const TabBarView(
children: [
Icon(Icons.directions_car),
Icon(Icons.directions_transit),
Icon(Icons.directions_bike),
],
),
),
),
);
}
}
OUTPUT

Create AppBar as a class flutter

i'm trying to make an appbar as a class for one of my page of my app (only used on 1 page).
I'd like to have addStoryAppBar for my code to be easier to read. How do I do this ? I've tried to create a widget, but it remove the leading back icon
class StoryAddPage extends StatefulWidget {
const StoryAddPage({Key key}) : super(key: key);
#override
_StoryAddPageState createState() => _StoryAddPageState();
}
class _StoryAddPageState extends State<StoryAddPage> {
#override
Widget build(BuildContext context) {
AppBar addStoryAppBar = AppBar(
backgroundColor: Colors.white,
title: Text(
AppLocalizations.of(context).add_story,
style: TextStyle(
color: AppColors.Black,
fontWeight: FontWeight.w700,
fontSize: 16),
),
leading: SvgPicture.asset(
"lib/assets/images/back.svg",
semanticsLabel: 'Back icon',
fit: BoxFit.none,
height: 10,
),
actions: [
GestureDetector(
child: Image.asset('lib/assets/images/select_picture.png'),
onTap: () => {},
),
Padding(
padding: const EdgeInsets.all(10.0),
child: ElevatedButton(
style: kOrangeButton,
onPressed: () => {},
child: Container(
child: Text(
AppLocalizations.of(context).publier,
style: TextStyle(color: AppColors.Black),
),
),
),
),
],
);
return SafeArea(
child: Scaffold(
appBar: addStoryAppBar,
body: Container(
child: Text('Add story'),
),
),
);
}
}
Also tried to extends the AppBar, but how do I pass the context ? Is this the more adapted thing to do ?
class StoryAppBar extends AppBar {
StoryAppBar()
: super(
iconTheme: IconThemeData(
color: Colors.black, //change your color here
),
backgroundColor: Colors.white,
title: Text(
AppLocalizations.of(context).add_story,
style: TextStyle(
color: AppColors.Black,
fontWeight: FontWeight.w700,
fontSize: 16),
),
elevation: 0.0,
automaticallyImplyLeading: false,
actions: <Widget>[
IconButton(
icon: Icon(Icons.notifications),
onPressed: () => null,
),
IconButton(
icon: Icon(Icons.person),
onPressed: () => null,
),
],
);
}
You can extract the AppBar widget to a statefull or stateless widget.
Create your own leading back icon. Just create Text Button, like this:
TextButton.icon(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(Icons.arrow_back_rounded),
label: Text(''),
),
Create a separate method that returns AppBar to your screen widget. Add the below method in a new class and call this method from anywhere you want to show AppBar
AppBar getApplicationAppBar(BuildContext context) {
return AppBar(
backgroundColor: Colors.white,
title: Text(
AppLocalizations
.of(context)
.add_story,
style: TextStyle(
color: AppColors.Black,
fontWeight: FontWeight.w700,
fontSize: 16),
),
leading: SvgPicture.asset(
"lib/assets/images/back.svg",
semanticsLabel: 'Back icon',
fit: BoxFit.none,
height: 10,
),
actions: [
GestureDetector(
child: Image.asset('lib/assets/images/select_picture.png'),
onTap: () => {},
),
Padding(
padding: const EdgeInsets.all(10.0),
child: ElevatedButton(
style: kOrangeButton,
onPressed: () => {},
child: Container(
child: Text(
AppLocalizations
.of(context)
.publier,
style: TextStyle(color: AppColors.Black),
),
),
),
),
],
);
}
If back button functionality not works, then use GestureDetector on Back Button
leading: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: SvgPicture.asset(
"lib/assets/images/back.svg",
semanticsLabel: 'Back icon',
fit: BoxFit.none,
height: 10,
),
),
if you have stateless widget you can Easily implement PreferredSizeWidget
this example show you how do that :
class CustomAppbar extends StatelessWidget implements
PreferredSizeWidget{
const CustomAppbar({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container();
}
#override
Size get preferredSize => Size(15.h, 100.w);
}
if you are using StatefulWidget you can copy paste this code
class CustomAppbar extends StatefulWidget implements PreferredSizeWidget {
final bool? isBack;
final TextEditingController? controller;
const CustomAppbar({Key? key, this.isBack, this.controller})
: super(key: key);
#override
State<CustomAppbar> createState() => _CustomAppbarState();
#override
Size get preferredSize => Size(15.h, 100.w);
}
class _CustomAppbarState extends State<CustomAppbar> {
#override
Widget build(BuildContext context) {
return Container()
}
}
and now you can use class on appbar
Scaffold(
appBar: CustomAppbar(
);
the rason for that if you enter to appbar you will see
/// An app bar to display at the top of the scaffold.
final PreferredSizeWidget? appBar;
the app bar is PreferredSizeWidget
and PreferredSizeWidget implement Widget Class
which contain get method
Size get preferredSize;

Flutter passing data and calling out method from a stateful widget to another statefulwidget

Good day! I have here some block of codes of my MainMenu page and Drawer.
I need to pass data from MainMenu which is a statefulwidget to Drawer which is also a statefulwidget so that I can use the datas and method from MainMenu.
Can someone help me or reproduce my code below.
class MainMenu extends StatefulWidget {
final VoidCallback signOut;
MainMenu(this.signOut);
#override
_MainMenuState createState() => _MainMenuState();
}
class _MainMenuState extends State<MainMenu> {
int index = 0;
List<Widget> list = [
HomeScreen(),
Stations(),
AccountPage(),
];
signOut() {
setState(() {
widget.signOut();
});
}
int currentIndex = 0;
String selectedIndex = 'TAB: 0';
String email = "", id = "", fname= "";
TabController tabController;
getPref() async {
SharedPreferences preferences = await SharedPreferences.getInstance();
setState(() {
id = preferences.getString('id');
email = preferences.getString('email');
fname = preferences.getString('fname');
});
print("id:" + id);
print("user:" + email);
print("address:" + fname);
}
#override
void initState() {
// TODO: implement initState
super.initState();
getPref();
}
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
actions: <Widget>[
IconButton(
onPressed: () {
signOut();
},
icon: Icon(Icons.lock_open),
)
],
backgroundColor: Color(0xFF262AAA),
iconTheme: IconThemeData(color: Colors.lightBlue),
centerTitle: true,
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('DVO',
style: TextStyle(color: Colors.lightBlue,fontWeight: FontWeight.w700),
),
SizedBox(width: 1.3),
Text(
'REPORT',
style: TextStyle(color: Colors.white,fontWeight: FontWeight.w700),
),
],
),
elevation: 0,
),
body: list[index],
drawer: MyDrawer(onTap: (lol, i) {
setState(() {
index = i;
Navigator.pop(lol);
});
}),
),
);
}
}
class MyDrawer extends StatefulWidget {
#override
_MyDrawerState createState() => _MyDrawerState();
}
class _MyDrawerState extends State<MyDrawer> {
Function onTap;
_MyDrawerState(
{this.onTap
});
#override
Widget build(BuildContext context) {
return SizedBox(
width: MediaQuery
.of(context)
.size
.width * 0.7,
child: Drawer(
child: Container(
color: Colors.white,
child: ListView(
padding: EdgeInsets.all(0),
children: <Widget>[
UserAccountsDrawerHeader(
decoration: BoxDecoration(
color: Colors.white,
image: DecorationImage(
image: AssetImage("assets/badge.jpg"),
fit: BoxFit.cover,
colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.8), BlendMode.dstATop)),
),
accountEmail: Text("dummy#gmail.com"),
accountName: Text("Dummy",
style: TextStyle(color: Colors.white,fontWeight: FontWeight.w700, fontSize: 25),
),
currentAccountPicture: CircleAvatar(
backgroundColor: Colors.grey[400],
child: Icon(
Icons.perm_identity,
color: Colors.white,
),
),
),
ListTile(
selected: true,
leading: Icon(Icons.announcement, color: Colors.cyan,size: 26.0),
title: Text("News And Announcements",
style: TextStyle(color: Colors.black,fontWeight: FontWeight.w500, fontSize: 18),
),
onTap: () => onTap(context, 0),
),
ListTile(
leading: Icon(Icons.place,color: Colors.cyan, size: 30.0),
title: Text("Stations",
style: TextStyle(color: Colors.black,fontWeight: FontWeight.w500, fontSize: 18),
),
onTap: () => onTap(context, 1),
),
ListTile(
leading: Icon(Icons.settings,color: Colors.cyan, size: 30.0),
title: Text("Account Settings",
style: TextStyle(color: Colors.black,fontWeight: FontWeight.w500, fontSize: 18),
),
onTap: () => onTap(context, 2),
),
Divider(
height: 595,
thickness: 0.5,
color: Colors.white.withOpacity(0.3),
indent: 32,
endIndent: 32,
),
ListTile(
leading: Icon(Icons.exit_to_app,color: Colors.cyan, size: 30.0),
onTap: () {
//widget.signOut();
},
title: Text("Logout",
style: TextStyle(color: Colors.black,fontWeight: FontWeight.w500, fontSize: 18),
),
),
],
),
),
),
);
}
}
I'm getting this error on build widget in MainMenu.
The named parameter 'onTap' isn't defined.
Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'onTap'.
This part:
Function onTap;
_MyDrawerState({this.onTap});
This parameter and its presence in the constructor should be in the MyDrawer public class rather than a private State class.
The specified error comes because MyDrawer class doesn't have this.
You can access onTap function in _MyDrawerState through the widget variable which is an instance of MyDrawer class