flutter code require ctrl+s to update the screen, setState() is not working - flutter

I am using provier in my app drawer to navigate to drawer menu screens... when i click on any item in drawer it does nothing but when i press ctrl+s it. takes me to the screen where i was supposed to go... where should i call setstate to automatically go to the desired screen without pressing ctrl+s
Here is my Drawer Code
class _DrawerClassState extends State<DrawerClass> {
#override
Widget build(BuildContext context) {
return Theme(
data: Theme.of(context).copyWith(
canvasColor: Colors.black,
),
child: Drawer(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
drawerTop("HI USER"),
ListView(
shrinkWrap: true,
children: [
drawerItems(context, "HOME", NavigationItem.home),
drawerItems(
context, "NOTIFICATIONS", NavigationItem.notifications),
drawerItems(context, "PARTNERS", NavigationItem.partner),
drawerItems(context, "LOCATIONS", NavigationItem.location),
drawerItems(context, "FEEDBACK", NavigationItem.feedback),
drawerItems(context, "CONTACT US", NavigationItem.contactus),
drawerItems(context, "AWARDS", NavigationItem.awards),
],
),
const Spacer(),
Padding(
padding: const EdgeInsets.symmetric(vertical: 20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.asset("assets/images/page6_boxes.png",
height: MediaQuery.of(context).size.height * 0.1),
Row(
children: [
SizedBox(width: MediaQuery.of(context).size.width * 0.1),
Image.asset(
"assets/images/facebook.png",
height: MediaQuery.of(context).size.height * 0.08,
),
Padding(
padding: EdgeInsets.symmetric(
horizontal:
MediaQuery.of(context).size.width * 0.05),
child: Image.asset(
"assets/images/insta_icon.png",
height: MediaQuery.of(context).size.height * 0.08,
),
),
],
),
],
),
)
],
),
),
);
}
drawerItems(
BuildContext context,
String title,
NavigationItem item,
) {
final provider = Provider.of<NavigationProvider>(context);
final currentItem = provider.navigationItem;
final isSelected = item == currentItem;
final color =
isSelected ? const Color.fromARGB(255, 243, 164, 1) : Colors.white;
return Padding(
padding: EdgeInsets.only(
top: 0.0, left: MediaQuery.of(context).size.width * 0.1),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
GestureDetector(
onTap: () {
selectItem(context, item);
},
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Text(
title,
style: TextStyle(
color: color,
fontFamily: "Raleway Reg",
fontSize: 23,
letterSpacing: 2),
),
),
),
SizedBox(
width: MediaQuery.of(context).size.width * 0.5,
child: const Divider(
thickness: 1,
color: Colors.white,
height: 3,
),
),
]));
}
}
void selectItem(BuildContext context, NavigationItem item) {
final provider = Provider.of<NavigationProvider>(context, listen: false);
provider.setNavigationItem(item);
}
Here is the code where i am switching screens
class MainPage extends StatefulWidget {
const MainPage({Key? key}) : super(key: key);
#override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
#override
Widget build(BuildContext context) => buildPages();
buildPages() {
final provider = Provider.of<NavigationProvider>(context, listen: false);
final navigationItem = provider.navigationItem;
switch (navigationItem) {
case NavigationItem.home:
return HomeScreen();
case NavigationItem.notifications:
return Notifications();
case NavigationItem.partner:
return Partners();
case NavigationItem.location:
return Locations();
case NavigationItem.feedback:
return FeedbackScreen();
case NavigationItem.contactus:
return const ContactUs();
case NavigationItem.awards:
return Awards();
}
}
}
here is provider class
class NavigationProvider extends ChangeNotifier {
NavigationItem _navigationItem = NavigationItem.home;
NavigationItem get navigationItem => _navigationItem;
void setNavigationItem(NavigationItem navigationItem) {
_navigationItem = navigationItem;
notifyListeners();
}
}
Please help

Related

Container is flickering or bouncing when notification value changed in ValueListenalbeBuilder

I have calendar text come from javascript using flutter_js. I used this calendar text widget in header widget as follow in home screen. Every time, navigate to home screen, screen is flickering or bouncing. If I take out this calendar widget, screen rendering is smooth.
If I put container height as follow, it is working as expected but I can't put the height because of the different size of screen.
Container(
height: 100,
padding:
const EdgeInsets.only(top: 10, left: 20, right: 20, bottom: 10),
child: const MyanmarCalender(),
),
myanmar_calender.dart
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_js/flutter_js.dart';
import 'package:intl/intl.dart';
class MyanmarCalender extends StatefulWidget {
const MyanmarCalender({Key? key}) : super(key: key);
#override
State<MyanmarCalender> createState() => _MyanmarCalenderState();
}
class _MyanmarCalenderState extends State<MyanmarCalender> {
final dateString = ValueNotifier("");
#override
void initState() {
super.initState();
try {
JavascriptRuntime jsRuntime = getJavascriptRuntime();
getMyanmardate(jsRuntime, "my-en").then(
(value) => {
dateString.value = value.toString(),
},
);
} catch (e) {
dateString.value = "";
if (kDebugMode) {
print('error: ${e.toString()}');
}
}
}
#override
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: dateString,
builder: (context, value, widget) {
return AutoSizeText(
value.toString().isEmpty ? '' :
'${value.toString()} (${DateFormat('d MMMM y').format(DateTime.now())})',
style: Theme.of(context).textTheme.caption,
textAlign: TextAlign.center,
maxLines: 3,
//overflow: TextOverflow.ellipsis,
);
});
}
Future<String> getMyanmardate(
JavascriptRuntime jsRuntime, String lang) async {
String mcalrsJs = await rootBundle.loadString("assets/js/mcalrs.js");
final jsResult = jsRuntime.evaluate("""${mcalrsJs}getCalender()""");
final jsStringResult = jsResult.stringResult;
return jsStringResult;
}
}
header.dart
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:thitsarparami/helper/constants.dart';
import 'package:thitsarparami/ui/home/components/myanmar_calender.dart';
class HeaderContainer extends StatelessWidget {
const HeaderContainer({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
final double screeWidth = MediaQuery.of(context).size.width;
final double screenHeight = MediaQuery.of(context).size.height;
return Container(
padding: const EdgeInsets.only(top: 30, left: 0, right: 0, bottom: 10),
width: screeWidth,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Expanded(
child: Container(
padding: const EdgeInsets.only(top: 20, left: 10, right: 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AutoSizeText(
kHomeTitle1,
style: Theme.of(context).textTheme.headline1,
maxLines: 1,
),
const SizedBox(
height: 5,
),
AutoSizeText(
kHomeTitle2,
style: Theme.of(context).textTheme.headline2,
maxLines: 1,
),
const SizedBox(
height: 5,
),
AutoSizeText(
kHomeTitle3,
style: Theme.of(context).textTheme.headline3,
maxLines: 1,
),
],
),
),
),
Container(
width: screeWidth * 0.40,
height: screenHeight * 0.19,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/buddha.png"),
fit: BoxFit.contain),
),
),
],
),
Container(
padding:
const EdgeInsets.only(top: 10, left: 20, right: 20, bottom: 10),
child: const MyanmarCalender(),
),
],
),
);
}
}
home_screen.dart
// ignore_for_file: prefer_const_constructors_in_immutables
import 'package:flutter/material.dart';
import 'package:thitsarparami/connectivity_wrapper/widgets/connectivity_screen_wrapper.dart';
import 'package:thitsarparami/ui/home/components/menu.dart';
import 'package:thitsarparami/widgets/base_widget.dart';
import 'components/header.dart';
class HomeScreen extends StatefulWidget {
static const routeName = '/home';
final BuildContext? menuScreenContext;
final Function? onScreenHideButtonPressed;
final bool hideStatus;
const HomeScreen(
{Key? key,
this.menuScreenContext,
this.onScreenHideButtonPressed,
this.hideStatus = false})
: super(key: key);
#override
HomeState createState() => HomeState();
}
class HomeState extends State<HomeScreen> {
#override
void initState() {
super.initState();
// try {
// throw Exception("Crash test");
// } catch (error, stack) {
// FirebaseCrashlytics.instance.recordError(error, stack, reason: "Test");
// }
}
#override
Widget build(BuildContext context) {
return BaseWidget(
child: Scaffold(
backgroundColor: Theme.of(context).backgroundColor,
body: ConnectivityScreenWrapper(
positionOnScreen: PositionOnScreen.BOTTOM,
child: SingleChildScrollView(
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Theme.of(context).primaryColorDark,
Theme.of(context).primaryColorLight,
],
begin: const FractionalOffset(0.0, 0.4),
end: Alignment.centerRight,
),
),
child: Column(
children: const [
HeaderContainer(),
MenuContainer(),
],
),
),
),
),
),
);
}
}

Not getting values when querying list in search bar implementation Flutter

I need some help when implementing the search bar funcionality in Flutter.
I am implementing flappy_search_bar: https://pub.dev/packages/flappy_search_bar
However, it does return any value when I try to search something.
Is there anything I am missing? Seems trivial this kind of implementations, just query some list and include the results in other list but I cannot figure out the way to do it.
class MainPage extends StatefulWidget {
const MainPage({Key? key}) : super(key: key);
#override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
TextEditingController textController = TextEditingController();
Future<List<dynamic>> search(String search) async {
await Future.delayed(Duration(seconds: 2));
List<dynamic> dogs = BreedList.where((dog) => dog['breed'].contains(search)).toList();
return dogs;
// return List(search.length, (int index) {
// return DogClass(breed: "$search $index");
// });
}
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Column(children: [
Container(
margin: const EdgeInsets.only(top: 60, bottom: 15),
padding: const EdgeInsets.only(left: 20, right: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Center(
child: Container(
width: MediaQuery.of(context).size.width -
(MediaQuery.of(context).size.width / 3.5),
height: 80,
child: SearchBar<dynamic>(
searchBarStyle: SearchBarStyle(borderRadius: BorderRadius.circular(20)),
onSearch: search,
cancellationWidget: Text('Cancel'),
emptyWidget: SizedBox.shrink(),
shrinkWrap:true,
onItemFound: (dynamic dogs, int index) {
return Container(
child: ListTile(
title: Text(dogs.breed.toString())
),
);
}),
//child: const Icon(Icons.search, color: Colors.white),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(Dimensions.radius20),
color: Colors.white),
),
)
],
),
),
//wrapping with this widgets the scroll problem is solved in list
const Expanded(
child: SingleChildScrollView(
child: BookPageBody(),
)),
]));
}
}

How can I send data from bottom sheet to parent widget?

I have list of products in bottom sheet, when I choose any product I want to parent's widget to add it, unfortunately my product adds only after hot reload, or when I create a new route from bottom sheet to parent's widget, how can I solve this problem, any ideas? Here is the part of the bottom sheet code
class IceBottomSheet extends StatefulWidget {
const IceBottomSheet({Key? key}) : super(key: key);
#override
_IceBottomSheetState createState() => _IceBottomSheetState();
}
class _IceBottomSheetState extends State<IceBottomSheet> {
final _model = ProductWidgetsModel();
#override
Widget build(BuildContext context) {
List<Widget> productWidgetList = [];
products.forEach((product) =>
productWidgetList.add(SingleProductWidget(product: product)));
return Provider(
model: _model,
child: Expanded(
child: GridView.count(
crossAxisSpacing: 10,
mainAxisSpacing: 16,
shrinkWrap: true,
crossAxisCount: 2, children: productWidgetList),
),
);
}
}
class SingleProductWidget extends StatefulWidget {
final Product product;
const SingleProductWidget({Key? key, required this.product})
: super(key: key);
#override
State<SingleProductWidget> createState() => _SingleProductWidgetState();
}
class _SingleProductWidgetState extends State<SingleProductWidget> {
#override
Widget build(BuildContext context) {
final model = Provider.of(context)?.model;
return Padding(
padding: const EdgeInsets.all(5.0),
child:
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SizedBox(
width: double.infinity,
height: 100,
child: DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
image: widget.product.image,
),
shape: BoxShape.circle,
border: Border.all(
color: model?.idSelected == widget.product.id
? Colors.yellow
: Colors.grey,
width: 5.0,
style: BorderStyle.solid,
),
),
child: GestureDetector(
onTap: () {
model?.idSelected = widget.product.id;
// Route route =
// MaterialPageRoute(builder: (context) => BerryPage(context,));
// Navigator.push(context, route);
if(model?.idSelected == 1){
menuRow.removeAt(2);
Navigator.pop(context);
choice.insert(2, Adds(id: 102, name: 'Холодок', img: 'https://autogear.ru/misc/i/gallery/73434/2759438.jpg'));
}
}),
),
),
And here is the part of parent's widget code, it is inside GestureDetector
else if (index == 2){
setState(() {
});
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (BuildContext builder) {
return Container(
height: 250,
child: Column(
children: [
SizedBox(
height: 10,
),Row(
children: [
Padding(
padding: EdgeInsets.only(left: MediaQuery.of(context).size.width*0.25 + MediaQuery.of(context).size.width *0.12),
child: Text(
'Холодок',
style: TextStyle(
fontFamily: 'Newfont',
fontSize: 22,
),
),
),
SizedBox(width: MediaQuery.of(context).size.width*0.25,),
IconButton(icon: Icon(Icons.close),onPressed: (){Navigator.pop(context);},)
],
),
Divider(),
IceBottomSheet(),
],
));
},
);
So when you open the BottomSheet you have to add await before it, so when you call Navigator.pop(context, data_you_want_to_pass_to_parent) it will wait for some data to be returned.
final data = await openBottomSheet();
inside the bottomSheet when you want to close, just pass the the desired data as so
Navigator.pop(context, data_you_want_to_pass_to_parent);

FlatButton taking up whole screen in flutter web

I am building a webapp with flutter where I want to add google sign in. The button itself works fine, but whatever I try, it just takes up my whole screen. I tried putting the button in the class in a container and putting it in a sizedbox on the page I actually want to use it on, and limiting the size of the button itself. This is my first time with flutter web, so I'd really like to know why this is happening.
Here is my code for the button:
class GoogleButton extends StatefulWidget {
#override
_GoogleButtonState createState() => _GoogleButtonState();
final DatabaseRepo databaseRepo;
final InitRepo initRepo;
GoogleButton(this.databaseRepo, this.initRepo);
}
class _GoogleButtonState extends State<GoogleButton> {
bool _isProcessing = false;
#override
Widget build(BuildContext context) {
return SizedBox(
height: MediaQuery.of(context).size.height / 10,
child: FlatButton(
height: MediaQuery.of(context).size.height / 10,
onPressed: () async {
setState(() {
_isProcessing = true;
});
await signInWithGoogle().then((result) {
print(result);
Navigator.of(context).pop();
Navigator.of(context).push(
MaterialPageRoute(
fullscreenDialog: true,
builder: (context) =>
MainPage(widget.databaseRepo, widget.initRepo),
),
);
}).catchError((error) {
print('Registration Error: $error');
});
setState(() {
_isProcessing = false;
});
},
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
child: _isProcessing
? CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(
Colors.blueGrey,
),
)
: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 20),
child: Text(
'Bejelentkezés',
style: TextStyle(
fontSize: 20,
color: Colors.blueGrey,
),
))
]))),
);
}
}
Just to be on the safe side, here is the code for the page itself:
import 'package:flutter/material.dart';
import 'package:foci_dev/repo/database_repo.dart';
import 'package:foci_dev/repo/init_repo.dart';
import 'package:foci_dev/ui/google_button.dart';
class SignInPage extends StatelessWidget {
final DatabaseRepo databaseRepo;
final InitRepo initRepo;
SignInPage(this.databaseRepo, this.initRepo);
#override
Widget build(BuildContext context) {
return Container(
color: Colors.grey[800],
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height / 5,
width: MediaQuery.of(context).size.height / 5,
child: Column(
children: [
Image(image: AssetImage('lib/assets/icon.png')),
Container(
height: MediaQuery.of(context).size.height / 10,
child: ButtonTheme(
height: 20,
child:
GoogleButton(this.databaseRepo, this.initRepo))),
],
)),
],
),
);
}
}
Thank you very much for your help, I really don't know what to do.

How to navigate to another page within a stack in flutter?

I am currently trying to manage the navigation logic within the flutter stack I have created.
I would like to add separate page navigation to each of the list items listed:
List<String> images = [
"assets/berries-chocolates-delicious-918327.jpg",
"assets/adult-beauty-cosmetic-1029896.jpg",
"assets/aerial-shot-architecture-beach-1488515.jpg",
"assets/brush-brushes-cosmetics-212236.jpg",
];
List<String> title = [
"Cadbury",
"Biotherme",
"Trip Advisor",
"L'Oreal Paris",
];
> This is the associated stack logic code in another file:
Stack(
children: <Widget>[
CardScrollWidget(currentPage),
Positioned.fill(
child: PageView.builder(
itemCount: images.length,
controller: controller,
reverse: true,
itemBuilder: (context, index) {
return Container();
},
),
)
],
),
// SizedBox(
// height: 10.0,
// ),
This is the associated widget file code:
import 'package:flutter/material.dart';
import '../screens/introductory_screen.dart';
import 'data.dart';
import 'dart:math';
import '../constants/constants.dart';
class CardScrollWidget extends StatefulWidget {
var currentPage;
CardScrollWidget(this.currentPage);
#override
_CardScrollWidgetState createState() => _CardScrollWidgetState();
}
class _CardScrollWidgetState extends State<CardScrollWidget> {
var padding = 20.0;
var verticalInset = 20.0;
#override
Widget build(BuildContext context) {
return new AspectRatio(
aspectRatio: widgetAspectRatio,
child: LayoutBuilder(builder: (context, contraints) {
var width = contraints.maxWidth;
var height = contraints.maxHeight;
var safeWidth = width - 2 * padding;
var safeHeight = height - 2 * padding;
var heightOfPrimaryCard = safeHeight;
var widthOfPrimaryCard = heightOfPrimaryCard * cardAspectRatio;
var primaryCardLeft = safeWidth - widthOfPrimaryCard;
var horizontalInset = primaryCardLeft / 2;
List<Widget> cardList = List();
for (var i = 0; i < images.length; i++) {
var delta = i - widget.currentPage;
bool isOnRight = delta > 0;
var start = padding +
max(
primaryCardLeft -
horizontalInset * -delta * (isOnRight ? 15 : 1),
0.0);
var cardItem = Positioned.directional(
top: padding + verticalInset * max(-delta, 0.0),
bottom: padding + verticalInset * max(-delta, 0.0),
start: start,
textDirection: TextDirection.rtl,
child: ClipRRect(
borderRadius: BorderRadius.circular(16.0),
child: Container(
decoration: BoxDecoration(
color: Colors.deepPurpleAccent,
boxShadow: [
BoxShadow(
color: Colors.black12,
offset: Offset(3.0, 6.0),
blurRadius: 10.0)
]),
child: AspectRatio(
aspectRatio: cardAspectRatio,
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Image.asset(
images[i],
fit: BoxFit.cover,
),
Align(
alignment: Alignment.bottomLeft,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(
horizontal: 16.0, vertical: 8.0),
child: Container(
decoration: BoxDecoration(
color: Colors.deepPurpleAccent,
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: const EdgeInsets.all(6.0),
This is where a gesture detector will be added to create a navigation link
child: Text(
title[i],
style: kCampaignLabelStyle,
),
),
),
),
This is where a gesture detector will be added to create a navigation link
// SizedBox(
// height: 10.0,
// ),
// Padding(
// padding: const EdgeInsets.only(
// left: 12.0, bottom: 12.0),
// child: Container(
// padding: EdgeInsets.symmetric(
// horizontal: 22.0, vertical: 6.0),
// decoration: BoxDecoration(
// color: Colors.deepPurpleAccent,
// borderRadius: BorderRadius.circular(20.0)),
// child: Text(
// "Read More",
// style: TextStyle(color: Colors.white),
// ),
// ),
// )
],
),
)
],
),
),
),
),
);
cardList.add(cardItem);
}
return Stack(
children: cardList,
);
}),
);
}
}
If anyone can help with the navigation logic, I would appreciate it.
create seperate files
Cadbury.dart
class Cadbury extends StatefulWidget {
#override
State<StatefulWidget> createState() {
return CadburyState();
}
}
class CadburyState extends State<DashboardApp> {
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text("Cadbury Screen"),
backgroundColor: MyColor.colorRed,
),
backgroundColor: MyColor.colorRed,
body: new Center());
}
}
Biotherme.dart
class Biotherme extends StatefulWidget {
#override
State<StatefulWidget> createState() {
return BiothermeState();
}
}
class BiothermeState extends State<Biotherme> {
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text("Biotherme Screen"),
backgroundColor: MyColor.colorRed,
),
backgroundColor: MyColor.colorRed,
body: new Center());
}
}
and make the redirections like this
// common function to create button and redirects the page which is in callback name
Widget buttonBuilder(
String buttonText, BuildContext context, Widget callbackName) {
return new RaisedButton(
child: Text(buttonText),
onPressed: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => callbackName));
});
}
// home redirection screen which redirects to the cadbury and Biotherme screen
class RedirectionScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(title: Text("Home Screen")),
body: Center(
child: new Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
buttonBuilder('Cadbury Screen', context, Cadbury()),
buttonBuilder('Biotherme Screen', context, Biotherme()),
],
),
));
}
}
try this below code for Navigation, it works for me
If you want to navigate the page on the button's click event then write code
return new RaisedButton(
child: Text(buttonText),
onPressed: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => redirection_page_name));
});
Note: Here redirection_page_name is the page or widget name which you want to be load on the button's click event.
The original syntax is
Navigator.push(context, MaterialPageRoute(builder: (context) => redirection_page_name));
here context is the current screen widget context which is built, and redirection_page_name is the new page/widget which is being loaded.