I use this method to show a AlertDialog:
_onSubmit(message) {
if (message.isNotEmpty) {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Center(child: Text('Alert')),
content: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children : <Widget>[
Expanded(
child: Text(
message,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.red,
),
),
)
],
),
actions: <Widget>[
FlatButton(
child: Text('Cancel'),
onPressed: () {
Navigator.of(context).pop();
}),
FlatButton(
child: Text('Ok'),
onPressed: () {
_inputTextController.clear();
Navigator.of(context).pop();
})
],
);
},
);
}
}
Everything is working but the buttons are aligned in right as shown on picture below:
I want to style some how the buttons, for example one on start other on end.
I searched in docs but only found how to make them "Stacked full-width buttons".
Any ideas how to style the buttons?
Update 2022/10/22
Flutter 2.5 introduced the actionsAlignment property:
AlertDialog(
title: ..
actions: ..
actionsAlignment: MainAxisAlignment.end
),
Customize widget
Edit the the widget itself: Under the AlertDialog there is a ButtonBar widget where you can use alignment: MainAxisAlignment.spaceBetween to align the buttons correctly. See this answer for an example of a custom AlertDialog widget.
Own button row
You could also remove the buttons under actions and add an own custom Row with RaisedButtons in it, somehow like this:
Row (
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
RaisedButton(), // button 1
RaisedButton(), // button 2
]
)
In your case you could add a Column around the Row in content and in there add your existing Row and the modified one you created from the above example.
Move buttons to content is a good solution.
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Center(child: Text('Alert')),
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
child: Text(
"message",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.red,
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
FlatButton(
child: Text('Yes'),
onPressed: () {
Navigator.of(context).pop();
}),
FlatButton(
child: Text('No'),
onPressed: () {
Navigator.of(context).pop();
})
])
],
),
);
});
Changing the theme is a good option.
MaterialApp(
theme: ThemeData(
buttonBarTheme: ButtonBarThemeData(
alignment: MainAxisAlignment.center,
)),
...
Don't add button in actions of AlertDialog. As you can see.
_onSubmit(message) {
if (message.isNotEmpty) {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Center(child: Text('Alert')),
content: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children : <Widget>[
Expanded(
child: Text(
message,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.red,
),
),
),
FlatButton(
child: Text('Cancel'),
onPressed: () {
Navigator.of(context).pop();
}),
FlatButton(
child: Text('Ok'),
onPressed: () {
_inputTextController.clear();
Navigator.of(context).pop();
})
],
),
);
},
);
}
}
I use this method to align buttons in actions of AlertDialog.
How this works::
The SizedBox takes the full width of the alertdialog using its context(In the statement MediaQuery.of(context).size.width. After that, a row is used which places space between its children in the main axis(mainAxisAlignment => the x-axis for a row).
AlertDialog style:
AlertDialog(
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Title'),
CloseButton(
color: Color(0xFFD5D3D3),
onPressed: () {
Navigator.of(context).pop();
})
]),
content: SingleChildScrollView(child: Text("Boby")),
actions: [
SizedBox(
width: MediaQuery.of(context).size.width,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ButtonTheme(
minWidth: 25.0,
height: 25.0,
child: OutlineButton(
borderSide: BorderSide(color: Colors.blueAccent),
child: new Text("Save"),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
onPressed: () {})),
SizedBox(width: 8.0),
ButtonTheme(
minWidth: 25.0,
height: 25.0,
child: OutlineButton(
borderSide: BorderSide(color: Colors.black26),
textColor: Colors.blue,
child: new Text("Close"),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
onPressed: () {}))
]))
]);
Here is the straightforward answer for your problem:
Just use actionsAlignment property of AlertDialog class in flutter. Like so
AlertDialog(
actions: ...,
actionsAlignment: MainAxisAlignment.spaceBetween
)
Or you can use RFlutter Alert library for that. It is easily customizable and easy-to-use. Its default style includes rounded corners and you can add buttons as much as you want.
Alert Style:
var alertStyle = AlertStyle(
animationType: AnimationType.fromTop,
isCloseButton: false,
isOverlayTapDismiss: false,
descStyle: TextStyle(fontWeight: FontWeight.bold),
animationDuration: Duration(milliseconds: 400),
alertBorder: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0.0),
side: BorderSide(
color: Colors.grey,
),
),
titleStyle: TextStyle(
color: Colors.red,
),
);
And assing your AlertStyle object to Alert's style field.
Alert(
context: context,
style: alertStyle,
type: AlertType.info,
title: "RFLUTTER ALERT",
desc: "Flutter is more awesome with RFlutter Alert.",
buttons: [
DialogButton(
child: Text(
"COOL",
style: TextStyle(color: Colors.white, fontSize: 20),
),
onPressed: () => Navigator.pop(context),
color: Color.fromRGBO(0, 179, 134, 1.0),
radius: BorderRadius.circular(0.0),
),
],
).show();
*I'm one of developer of RFlutter Alert.
Related
How to make two buttons expand equally over the entire width of the Navigation Drawer?
The main thing will be
ListTile(
title: Row(
children: <Widget>[
Expanded(child: RaisedButton(onPressed: () {},child: Text("Clear"),color: Colors.black,textColor: Colors.white,)),
Expanded(child: RaisedButton(onPressed: () {},child: Text("Filter"),color: Colors.black,textColor: Colors.white,)),
],
),
)
Complete Code
class SO extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
drawer: Drawer(
child: 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
// ...
},
),
ListTile(
//contentPadding: EdgeInsets.all(<some value here>),//change for side padding
title: Row(
children: <Widget>[
Expanded(child: RaisedButton(onPressed: () {},child: Text("Clear"),color: Colors.black,textColor: Colors.white,)),
Expanded(child: RaisedButton(onPressed: () {},child: Text("Filter"),color: Colors.black,textColor: Colors.white,)),
],
),
)
],
),
),
);
}
}
This worked for me
Row(
children: <Widget>[
RaisedButton(
onPressed: () {
Route route =
MaterialPageRoute(builder: (context) => MinionFlare());
Navigator.push(context, route);
},
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.4,
child: Text("Minion"),
),
),
RaisedButton(
onPressed: () {
Route route = MaterialPageRoute(
builder: (context) => EmojiRatingBar());
Navigator.push(context, route);
},
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.4,
child: Text("Emoji")),
),
],
),
You can wrap each button with Expanded.
Row(
children : <Widget>[
Expanded(
child: Button(
child: Text("Clear")
)
),
Expanded(
child: Button(
child: Text("Filter")
)
),
])
Container(
height: 100,
child: Row(
children : <Widget>[
Expanded(
child: RaisedButton(
onPressed: () {},
color: Color(0xff0000ff),
child: Text("Left Button", style: TextStyle(color: Colors.white),)
)
),
Expanded(
child: RaisedButton(
onPressed: () {},
color: Color(0xffd4d4d4),
child: Text("Right Button")
)
),
])
)
This is my code, copied from here:
SliverAppBar(
expandedHeight: 150.0,
flexibleSpace: const FlexibleSpaceBar(
title: Text('Available seats'),
),
actions: < Widget > [
IconButton(
icon: const Icon(Icons.add_circle),
tooltip: 'Add new entry',
onPressed: () { /* ... */ },
),
]
)
But I need to add a Drawer. How can I do that?
I am trying to rebuild my app in Flutter.
Converting java android app to flutter
I replaced the icon but how can I create a Drawer?
leading: IconButton(icon: Icon( Icons.menu ),onPressed: ()=>{},)
My full code
#override
Widget build(BuildContext context) {
return NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
leading: IconButton(
icon: Icon(Icons.menu),
onPressed: () => {},
),
actions: <Widget>[
IconButton(
onPressed: () => {},
icon: Icon(Icons.shopping_cart),
)
],
expandedHeight: 200.0,
floating: false,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text("My Pet Shop",
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
)),
background: Image.network(
"https://firebasestorage.googleapis.com/v0/b/my-pet-world.appspot.com/o/images%2Fbannerads%2FxTmAblJI7fMF1l0nUa1gM32Kh9z1%2F734rm6w7bxznp%2FPETWORLD-HOME-SLIDER-KITTENS.webp?alt=media&token=cf7f48bb-6621-47b3-b3f8-d8b36fa89715",
fit: BoxFit.cover,
)),
),
];
},
body: Container(
margin: EdgeInsets.only(top: 0),
child: Column(
children: <Widget>[
Expanded(
//getHomePageWidget()
child: ListView(
padding: EdgeInsets.all(0.0),
children: <Widget>[getHomePageWidget()],
),
)
],
),
));
}
Drawer is a property for Scaffold. Once you set a drawer property, the menu icon will automatically appear in the SliverAppBar.
Return this inside your build method, and you will get what you are looking for.
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
expandedHeight: 200.0,
flexibleSpace: const FlexibleSpaceBar(
title: Text('Available seats'),
),
actions: <Widget>[
IconButton(
icon: const Icon(Icons.add_circle),
tooltip: 'Add new entry',
onPressed: () {},
),
],
),
SliverList(
delegate: SliverChildListDelegate([
getHomePageWidget(),
]),
),
],
),
drawer: Drawer(),
);
NOTE: if you have multiple Scaffold in the tree above the CustomScrollView than the Drawer should be in the most bottom Scaffold
Following is a simple code(in main.dart) I was trying to use to revisit the flutter basics which I was doing few months back.
Here, in the following code setState() is not working as expected and the reason is with the wrong state.
I can get it usable by creating separate statefulwidget withs states constituting the following elements for button and text change.
But here I wanted to know is it possible to do it anonymously with minimal changes in below code
import 'package:flutter/material.dart';
var textStrings = ["Hello", "Hi", "Hey", "Aloha"];
var counter = 0;
void main() => runApp(MaterialApp(
title: "Hello",
home: Scaffold(
appBar: AppBar(
title: Text(
"First App",
style: TextStyle(
color: Colors.white70,
fontSize: 20,
fontStyle: FontStyle.normal),
),
),
body: Container(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(padding: EdgeInsets.only(top: 20)),
Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(padding: EdgeInsets.only(bottom: 20)),
Center(
child: Text("With Flutter, Spread Fluttery",
style: TextStyle(
color: Colors.redAccent,
fontStyle: FontStyle.italic,
fontSize: 30)),
),
Padding(padding: EdgeInsets.only(bottom: 20)),
Icon(
Icons.refresh,
size: 50,
color: Colors.amberAccent,
),
Padding(padding: EdgeInsets.only(bottom: 20)),
Text(textStrings[counter % 4],
style: TextStyle(
color: Colors.black38,
fontSize: 30,
fontStyle: FontStyle.normal)),
Padding(padding: EdgeInsets.only(bottom: 20)),
RaisedButton(
onPressed: () {
setState() {
counter++;
}
},
child: Text("Enter",
style: TextStyle(
color: Colors.teal,
fontSize: 30,
)),
)
],
),
)
],
),
),
),
),
));
Sure you can do it adding a few lines of code, you can use the StatefulBuilder.
Wrap your container inside StatefulBuilder and change your setState(() {} ) inside the onPressed method of your button.
void main() => runApp(MaterialApp(
title: "Hello",
home: Scaffold(
appBar: AppBar(
title: Text(
"First App",
style: TextStyle(
color: Colors.white70,
fontSize: 20,
fontStyle: FontStyle.normal),
),
),
body: StatefulBuilder(
builder: (context, setState) {
return Container(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(padding: EdgeInsets.only(top: 20)),
Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(padding: EdgeInsets.only(bottom: 20)),
Center(
child: Text("With Flutter, Spread Fluttery",
style: TextStyle(
color: Colors.redAccent,
fontStyle: FontStyle.italic,
fontSize: 30)),
),
Padding(padding: EdgeInsets.only(bottom: 20)),
Icon(
Icons.refresh,
size: 50,
color: Colors.amberAccent,
),
Padding(padding: EdgeInsets.only(bottom: 20)),
Text(textStrings[counter % 4],
style: TextStyle(
color: Colors.black38,
fontSize: 30,
fontStyle: FontStyle.normal)),
Padding(padding: EdgeInsets.only(bottom: 20)),
RaisedButton(
onPressed: () {
setState(() {
counter++;
});
},
child: Text("Enter : $counter",
style: TextStyle(
color: Colors.teal,
fontSize: 30,
)),
)
],
),
)
],
),
),
);
},
)),
));
First, you need to understand that, whenever you call setState() method, It will just rebuild the Stateful Widget, and build() method of the State class of Stateful widget gets executed.
In your code, there is no such stateful widget is available so setState() method is of no use.
Here is the code:
void main() => runApp(MaterialApp(
title: "Hello",
home: Scaffold(
appBar: AppBar(
title: Text(
"First App",
style: TextStyle(
color: Colors.white70,
fontSize: 20,
fontStyle: FontStyle.normal),
),
),
body: MyAppWidgets(),
),
)
);
class MyAppWidgets extends StatefulWidget {
#override
_MyAppWidgetsState createState() => _MyAppWidgetsState();
}
class _MyAppWidgetsState extends State<MyAppWidgets> {
var textStrings = ["Hello", "Hi", "Hey", "Aloha"];
var counter = 0;
#override
Widget build(BuildContext context) {
return Container(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(padding: EdgeInsets.only(top: 20)),
Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(padding: EdgeInsets.only(bottom: 20)),
Center(
child: Text("With Flutter, Spread Fluttery",
style: TextStyle(
color: Colors.redAccent,
fontStyle: FontStyle.italic,
fontSize: 30)),
),
Padding(padding: EdgeInsets.only(bottom: 20)),
Icon(
Icons.refresh,
size: 50,
color: Colors.amberAccent,
),
Padding(padding: EdgeInsets.only(bottom: 20)),
Text(textStrings[counter % 4],
style: TextStyle(
color: Colors.black38,
fontSize: 30,
fontStyle: FontStyle.normal)),
Padding(padding: EdgeInsets.only(bottom: 20)),
RaisedButton(
onPressed: () {
setState(() {
counter++;
});
},
child: Text("Enter",
style: TextStyle(
color: Colors.teal,
fontSize: 30,
)),
)
],
),
)
],
),
),
);
}
}
i think that there is no way to do so, because runApp is can not redraw using statefull widget. it is just starting point of your application.
just change the title of your application in main method and use hot reload it will not reflated in you result and use play button(run button) it will work.
I want to my card button fit together like Reddit App. How can do that?
Outside the main Row has a Container and Container' has padding height 15.0 . How can Row's widget fit that height 15.0 responsively.
Reddit card buttons
My app card buttons
This is my code;
#override
Widget build(BuildContext context) {
return new SafeArea(
top: false,
bottom: false,
child: new Card(
child: new Column(
children: <Widget>[
new Container(
padding: EdgeInsets.fromLTRB(5.0, 15.0, 5.0, 3.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Container(
color: Colors.blueGrey,
child: new Row(
children: <Widget>[
new Icon(Icons.arrow_drop_up),
new Text('Vote'),
new Icon(Icons.arrow_drop_down),
],
),
),
new Container(
color: Colors.blueGrey,
child: new Row(
children: <Widget>[
new Icon(Icons.mode_comment),
new Text('Comment'),
],
),
),
new Container(
color: Colors.blueGrey,
child: new Row(
children: <Widget>[
new Icon(Icons.share),
new Text('Share'),
],
),
),
],
),
)
],
),
),
);
}
Hello and welcome to Flutter :)
First of all you have used too much padding i.e. 15.0 so that is why your grey boxes are smaller than that of Reddit example.
I have taken a simpler approach and designed a sample control for you. Hope you like it.
import 'package:flutter/material.dart';
void main() {
runApp(RedditButtonsExample());
}
class RedditButtonsExample extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: "Reddit Buttons Example",
home: HomePage(),
theme: ThemeData(
primaryColor: Colors.white,
accentColor: Colors.white,
),
);
}
}
class HomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Reddit Buttons Example'),
),
body: Column(
children: <Widget>[
Expanded(child: Icon(Icons.insert_emoticon)),
RedditButtonsCard(), //Example widget.
],
),
);
}
}
//This is the example control that you need.
class RedditButtonsCard extends StatelessWidget {
const RedditButtonsCard({
Key key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Card(
color: Colors.black,
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
FlatButton.icon(
textColor: Colors.white,
icon: Icon(
Icons.thumbs_up_down,
color: Colors.white,
),
label: Text('Vote'),
onPressed: () {},
),
FlatButton.icon(
color: Colors.white30,
textColor: Colors.white,
icon: Icon(
Icons.mode_comment,
color: Colors.white,
),
label: Text('Comment'),
onPressed: () {},
),
FlatButton.icon(
textColor: Colors.white,
icon: Icon(
Icons.share,
color: Colors.white,
),
label: Text('Share'),
onPressed: () {},
),
],
),
),
);
}
}
I used Table and TableRow and I found what I wanted. Off the topic but I want to say this; I found this solution in my dream. I said my self "you have to use DataTable or something then you got what you want." My subconscious full of with Flutter I guess. :D
#override
Widget build(BuildContext context) {
return new SafeArea(
top: false,
bottom: false,
child: new Card(
child: new Column(
children: <Widget>[
new Table(
children: [
new TableRow(
children: [
new InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.fromLTRB(5.0, 15.0, 5.0, 15.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Icon(FontAwesomeIcons.arrowAltCircleUp, color: Colors.white),
Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: new Text('Vote', style: TextStyle(color: Colors.white)),
),
new Icon(FontAwesomeIcons.arrowAltCircleDown, color: Colors.white),
],
),
),
),
new InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.fromLTRB(5.0, 15.0, 5.0, 15.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Icon(Icons.mode_comment, color: Colors.white),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text('Comment', style: TextStyle(color: Colors.white)),
),
],
),
),
),
new InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.fromLTRB(5.0, 15.0, 5.0, 15.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Icon(Icons.share, color: Colors.white),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text('Share', style: TextStyle(color: Colors.white)),
),
],
),
),
),
],
),
],
),
],
),
),
);
}
I am currently looking at Navigating withing different screens in my app and so far I can Navigate from LoginScreen to EventsScreen successfully. The problem is in EventsScreen there is a button if clicked it should take me to LoginScreen and this is the code I have.
in my events_screen.dart file
and in my app.dart file MaterialApp widget I have my routes as
The Holiday flatbutton when clicked it does not take me to the "/HolidayScreen" route.
How can I solve the [dart] Undefined name 'context'?
events_screen.dart
import 'package:flutter/material.dart';
import 'holiday.dart';
class EventsScreen extends StatelessWidget {
Widget build(context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.white,
body: Container(
alignment: Alignment.center,
margin: EdgeInsets.all(20.0),
child: ListView(
children: <Widget>[
Container(margin: EdgeInsets.only(bottom: 20.0)),
eventsButton(),
Container(margin: EdgeInsets.only(bottom: 20.0)),
],
),
),
),
);
}
Widget eventsButton() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
color: Colors.red[800],
onPressed: () {},
child: Text(
'Events',
style: new TextStyle(color: Colors.white, fontWeight: FontWeight.normal),
),
),
Container(margin: EdgeInsets.only(right: 20.0)),
FlatButton(
color: Colors.red[800],
child: Text(
'Holidays',
style: new TextStyle(color: Colors.white, fontWeight: FontWeight.normal),
),
onPressed: () {
Navigator.pushNamed(context, "/Holiday");
},
),
Container(margin: EdgeInsets.only(right: 20.0)),
FlatButton(
color: Colors.red[800],
onPressed: () {},
child: Text(
'Flights',
style: new TextStyle(color: Colors.white, fontWeight: FontWeight.normal),
),
),
],
);
}
}
Easy, just pass the BuildContext into your eventsButton method
Widget build(context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.white,
body: Container(
alignment: Alignment.center,
margin: EdgeInsets.all(20.0),
child: ListView(
children: <Widget>[
Container(margin: EdgeInsets.only(bottom: 20.0)),
eventsButton(context),
Container(margin: EdgeInsets.only(bottom: 20.0)),
],
),
),
),
);
}
And add a parameter in your method
Widget eventsButton(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment
//...
UPDATED
And change this :
Navigator.pushNamed(context, "/Holiday");
To this:
Navigator.pushNamed(context, "/HolidayScreen");
Because your route name is HolidayScreen not Holiday
Make your method accept your context as a parameters
Widget eventsButton(BuildContext context)
and call it with the context: eventsButton(context),