Flutter Floating Action Button with Dynamic Status - flutter

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')
);

Related

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.

I want to show details to the right side of screen after clicking an item on left, flutter

[I want to do something like this][1]
I want to show details to the right side of screen after clicking an item on left for my web app
[1]: https://i.stack.imgur.com/6P4Oq.png
body:child:Row[
TabBarView(
physics: NeverScrollableScrollPhysics(),
children: [
OngoingOrder(),//listview inside each view
CompletedOrder(),
CancelledOrder(),
]),
),
ShowOrder(
//rightside of page
)
]),
),
please post your existing code to understand
what logic you have performed.
If you are using any state management tool then please also mention that.
pseudocode: (flutter basic without any state management)
1)create a null Object for the right side
2)perform a null check to show the default demo message "Select An Order to see"
3)when user select an Order, populate the created object with the selected data and call setState((){})

Flutter Image Hovering Overlay Effect

I am working on a flutter web project and I want to the following overlay effect over my image that whenever the cursor hovers over the image, a few buttons should show up, and the opacity of the image gets reduced (or blurred out) while hovering.
I have tried InkWell and GestureDectector but nothing seems to work.
This is basically what I am trying to achieve : Preview.
Try using hovering package to achieve the hovering effect on flutter_web.
First, import the package:
import 'package:hovering/hovering.dart';
Add a GlobalKey within your StatelessWidget:
final _key = GlobalKey<ScaffoldState>();
And then, use the HoverWidget:
HoverWidget(
hoverChild: Container(
height: 200,
width: 200,
color: Colors.green,
child: Center(child: Text('Hover Me..')),
),
onHover: (event) {
_key.currentState.showSnackBar(SnackBar(
content: Text('Yaay! I am Hovered'),
));
},
child: Container(
height: 200,
width: 200,
color: Colors.red,
child: Center(child: Text('Hover Me..')),
),
)
Check the example use case here
Hi Raj this is pretty simple
You just need to use Listener Widget which detects onPointerHover and update you app's state
Here is the api link follow it
Listener in Flutter
If any difficulties comment down below
Okay, over time I have tried many ways and would like to share my insight in case somebody else is looking for the same solution too.
So, the basic way to achieve this is to use the Hovering package.
Another way would be to use MouseRegion.
You can use the onEnter and onExit property of MouseRegion to detect when did the cursor entered and left the region/container you are trying to add a hove effect to.
You can use that to switch between your different app states.
Or it has onHover property as well, that basically tells that if the cursor is currently hovering that region or not you can use that too.
Note: I tried the Listener widget as well, but either I didn't understood it well, or it was too complicated to work with. Anyways, I couldn't achieve what I wanted.

In Flutter, How does one create a 'how this app works' walk-through?

I want to launch a simple walk-through for our app. The user would log in for the first time (or select the 'tutorial' option in settings), and it would walk you through how to use the app.
To clarify, the app would launch a dialog/alertdialog and the background would go grey or become greyed out highlighting specific areas/buttons of the app to talk them through it. The dialog box would have a child of Text explaining how to use it.
After the user has clicked through the steps the tutorial would end but could be reactivated in settings.
Any help would be appreciated.
Thanks
There is a plugin called showcaseview and does pretty much what you want. You can get it here. For using it you need to wrap the page you want to show in a ShowCaseWidget
ShowCaseWidget(
builder: Builder(
builder : (context) () => Somewidget()
),
),
then for every part of the page you want to show a guide for it, wrap it in a ShowCase
Showcase(
key: _one,
title: 'Menu',
description: 'Click here to see menu options',
child: Icon(
Icons.menu,
color: Colors.black45,
),
),

Does anyone know how to make an http request in 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.