flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.99k stars 27.19k forks source link

Undefined name 'context'. Try correcting the name to one that is defined #72220

Closed VasiiH closed 3 years ago

VasiiH commented 3 years ago

GestureDetector( onTap: () => Navigator.push( context, // here it shows undefined name 'context' MaterialPageRoute( builder: (_) => RestaurantScreen(restaurant: restaurant), ), ),

iapicca commented 3 years ago

@VasiiH the error most likely depends from your implementation rather than a bug with flutter nevertheless can you provide, together with your flutter doctor -v a complete reproducible minimal code sample, not a snippet from production code

VasiiH commented 3 years ago

thank you for your support, i solve the problem

On Sun, Dec 13, 2020 at 2:03 PM Francesco Iapicca notifications@github.com wrote:

@VasiiH https://github.com/VasiiH the error most likely depends from your implementation rather than a bug with flutter nevertheless can you provide, together with your flutter doctor -v a complete reproducible minimal code sample, not a snippet from production code

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/flutter/flutter/issues/72220#issuecomment-743973657, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJT24N3RJQLT24VUN4FKEZ3SUR357ANCNFSM4UZF2WTQ .

iapicca commented 3 years ago

thank you for your support, i solve the problem

@VasiiH if the problem is solved please close the issue

Azor3 commented 3 years ago

How did you solve can u share it with me?

VasiiH commented 3 years ago

Sure, i have used StatelessWidget thats why i got that error, i change to StatefullWidget then its working fine

On Sun, 13 Dec 2020, 7:02 p.m. Azor3, notifications@github.com wrote:

How did you solve can u share it with me?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/flutter/flutter/issues/72220#issuecomment-744008508, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJT24NYBYOBT3XCB6UKURL3SUS67RANCNFSM4UZF2WTQ .

Azor3 commented 3 years ago

I'm already using StatefullWidget but I have the same problem idk why

VasiiH commented 3 years ago

the error most likely depends from your implementation rather than a bug with flutter nevertheless can you provide, together with your flutter doctor -v a complete reproducible minimal code sample, not a snippet from production code

On Sun, 13 Dec 2020, 7:15 p.m. Azor3, notifications@github.com wrote:

I'm already using StatefullWidget but I have the same problem idk why

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/flutter/flutter/issues/72220#issuecomment-744010221, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJT24NYE3D5D4OFJAGDXQETSUTAORANCNFSM4UZF2WTQ .

Azor3 commented 3 years ago

Ok, I fixed it thanks for your time.

VasiiH commented 3 years ago

Great, thanks!

On Sun, 13 Dec 2020, 7:25 p.m. Azor3, notifications@github.com wrote:

Ok, I fixed it thanks for your time.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/flutter/flutter/issues/72220#issuecomment-744011429, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJT24N3O4PU4ORVZ2OGUNRTSUTBVBANCNFSM4UZF2WTQ .

Waad-Alatiyat commented 3 years ago

Ok, I fixed it thanks for your time.

How did you fix it?

Shadow-coder1 commented 3 years ago

I am having the same problem with the context and I am already using a stateful widget any solution, please?

Future login()async{ var url = ("https://blest-cloud.000webhostapp.com/signup.php") ; var res = await http.post(Uri.parse(url),body: { "email":_emailController.text, "password":_passwordController.text,

});
print (res.body);
var data = jsonDecode(res.body);
if(data == "Success"){
  Fluttertoast.showToast(
    msg: "Login Successfully",
    toastLength: Toast.LENGTH_SHORT,
    gravity: ToastGravity.CENTER,
    timeInSecForIosWeb: 1,
    backgroundColor: Colors.red,
    textColor: Colors.white,
    fontSize: 16.0,
  );

  Navigator.push(context, MaterialPageRoute(builder:(_)=>Mainpage()));
}else{
  Fluttertoast.showToast(
      msg: "login denied",
      toastLength: Toast.LENGTH_SHORT,
      gravity: ToastGravity.CENTER,
      timeInSecForIosWeb: 1,
      backgroundColor: Colors.green,
      textColor: Colors.white,
      fontSize: 16.0
  );
}

}

Jaymal1 commented 3 years ago

I am having the same problem with the context and I am already using a stateful widget any solution, please?

Future login()async{ var url = ("https://blest-cloud.000webhostapp.com/signup.php") ; var res = await http.post(Uri.parse(url),body: { "email":_emailController.text, "password":_passwordController.text,

});
print (res.body);
var data = jsonDecode(res.body);
if(data == "Success"){
  Fluttertoast.showToast(
    msg: "Login Successfully",
    toastLength: Toast.LENGTH_SHORT,
    gravity: ToastGravity.CENTER,
    timeInSecForIosWeb: 1,
    backgroundColor: Colors.red,
    textColor: Colors.white,
    fontSize: 16.0,
  );

  Navigator.push(context, MaterialPageRoute(builder:(_)=>Mainpage()));
}else{
  Fluttertoast.showToast(
      msg: "login denied",
      toastLength: Toast.LENGTH_SHORT,
      gravity: ToastGravity.CENTER,
      timeInSecForIosWeb: 1,
      backgroundColor: Colors.green,
      textColor: Colors.white,
      fontSize: 16.0
  );
}

}

login(BuildContext context) async................... should solve the problem dont forget to call context whenever you use login()

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.