Does anyone know how to make an http request in flutter? - flutter

I need to make an app in which the user needs to press an InkWell or a button and then it should take them to a website, so does anyone know how to do this?

There is a really nice plugin for this, called url_launcher. Usage is as follows:
InkWell(
onTap: () => launch(websiteUrl),
...
)
You can also use canLaunch to test if launching will work. More on that in README.md.

Related

Call a function when user press a Key from Keyboard in Flutter

how can I call a function when the user presses a key from the keyboard ?
This is for Desktop development .
You can do it using Actions and shortcuts in flutter. These widgets work something like this :
To get a more detailed information, please refer to the flutter docs here. These come under Advanced UI concepts.
I imagine you're using a TextField? It has the following property onChanged: ((newText) => {})
You can go ahead and use it like this:
onChanged: ((newText) => { yourFunction; }),
or
onChanged: ((newText) => { setState((){yourFunction;}); }),
Just to clarify, this will only update when the text changes. #Divyam Dhadwal seems to have a wild answer that might be more useful
Good luck my man! xx

Flutter InkWell widget color not updating after Tap

I am having trouble coding a function. In my app, a quiz has been added, the quiz functionality works, the quiz data is retrieved from a server and delivered as JSON data. I have a problem where my app does not show whether a user's answer is correct or not when they select an answer but will only do so if the user leaves the screen and then returns. Using a function that returns a color, the correct and incorrect answers are presented. However, I am unsure what the problem is; how can I solve it?
I would like to provide the code but it is a lot, so you can find it here: https://github.com/BotsheloRamela/code
Most of the functionality can be found here in the main code: https://github.com/BotsheloRamela/code/blob/main/option.dart
If you're having trouble with that then make sure to do it so
Material(
child: InkWell(
child : Ink()));
// and populate this accordingly

Flutter web update url/route base on state

I'm new in flutter and I just want to know if this scenario/feature is possible in flutter/flutter web. I want to update the url/route base on the state of the screen. For example, in 9gag.com, there are buttons for Hot, Trending, and Fresh. Then, if I clicked the Hot button its url will be updated to 9gag.com/hot and also its contents, the same goes for Trending and Fresh buttons. Is this possible in flutter/flutter web? If so, how do I implement this feature?(much better if the implementation uses bloc)
Totally possible and is very easy to achieve just use url_launcher Package on onpressed/ontap
Example: Add this code somewhere like in the beginning of your stateful management or at the end of your code
_launchURL() async {
const url = 'https://flutter.io';
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Call it somewhere like this
RaisedButton(
onPressed: _launchURL,
child: new Text('Show Flutter homepage'),
),
),
Now if you have some 9gag/hot button or container whatever you are going with just put that url and when user taps it, it will open that url. If you want to open it inside the app webview that's also possible but slightly different.
If I understood correctly It's pretty straightforward use the default way of navigation and routing.
I'm not sure with your approach like you have mentioned
I want to update the url/route base on the state of the screen
and
Then, if I clicked the Hot button its url will be updated to 9gag.com/hot and also its contents
If I'm not wrong there is a inbuilt feature of navigating to other screens and once you land on the desired screen, you can see the refreshed content. If you want to try material design the code will be like this
//within your stateful or stateless widget
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => YourPage()),
Instead of using a package you can try this inbuilt way of doing the same job. But it's upto you which one you want to use. Checkout the official flutter documentation https://flutter.dev/docs/cookbook/navigation
I hope this approach also helps to answer your question. If so happy to help in your flutter journey, if not share that how did you solved it.

Why is there no back button in the Flutter Navigator 2.0 Example?

as I started working on a Flutter application I came across the Navigator 2.0. As the Documentation suggested, I used the code provided in the Documentation by John Ryan: https://medium.com/flutter/learning-flutters-new-navigation-and-routing-system-7c9068155ade.
My Problem is that the example without a nested navigation has an automatically displayed back button but the example with nested navigation does not. Why is that the case and is there a way to let the back button be automatically generated?
I am using the Flutter 1.25.0-8.2.pre beta channel.
Thank you in advance!
Your handler should indicate that the enclosing route should not be closed, hence returning false will resolve your issue.
changing your handler to this works:
onWillPop: () async {
navigatorKey.currentState.maybePop();
return false;
},
I could not really solve this issue. As far as I can see, it has something to do with the nested Router delegates. However, I have implemented a flattened structure which uses only one router delegate and it works fine.

Flutter Floating Action Button with Dynamic Status

Putting the finishing touches on my first Flutter mobile app.
Another important ToDo: My Floating Action Button appears in the Top App Bar for every page, but i would like its status to change (enabled / disabled) depending on the current page. Is this possible? if so, any tutorials, resources, reference material and / or code examples fit for a novice, would be much appreciated.
Thanks!
Cool, you can use Visibility:
floatingActionButton: Visibility(
child: FloatingActionButton(...),
visible: false, // set it to false
)
Alternatively, you could use NotificationListener (more elegante but sophisticated).
Please check this example from another publication
Edit: maybe controlling it directly in onPressed.
According to official docs:
"If the onPressed callback is null, then the button will be disabled and by default will resemble a flat button in the disabledColor."
FloatingActionButton(
onPressed: shouldButtonBeDisabled() ? null : () => whatToDoOnPressed,
child: Text('blablabla')
);