VK Like Widget: show 0 instead of +1 - vk

In VK Like Widget, in counters, is there any way to show 0 instead of +1 when nobody likes item? I'm initializing my button via
VK.Widgets.Like("vk_like", {type: "button", pageUrl: absUrl});

Related

How to set a widget as a button in Flutter

I set two widgets in a Stack(), the one in the back is a sidebar and the one in the front is my main page.
When I click on the menu button from the main page, the main page gets shifted to the right and then the user can see the sidebar.
Now the problem is when the sidebar gets displyed i'm obliged to click exactly on the menu button to go back to the main page.
What i want to do is just to click anywhere in the main page to hide the sidebar.
I mean that i want to set the whole main page as a button when the sidebar is displayed.
You can use InkWell
InkWell(
onTap: (){
/// do something
},
child: Text('data') /// your widget,
),
You can also use GestureDetector
Generally if you want to make anything tappable you can just wrap the widget with GestureDetector
I fixed it by wrapping the main page with InkWell() and I added this to the onTap property"
InkWell(
onTap: isSidebarCollapsed ? () {
setState(() {
isSidebarCollapsed = false;
});
} : null,
child: Container(...)
)
Note that isSidebarCollapsed is the variable that determines if the menu is displayed or not.
Explaination of the code:
If the sidebar is collapsed (is displayed) then the onTap property returns a function where I set the variable isSidebarCollapsed to false (to say that the sidebar is gonna be hidden).
Else it returns null

Flutter floating button hide and show on whether ListView index

I have an app that has a ListView and Floating Button. I wanted to hide the Floating Button if Index 0 in the ListView is shown and show the Floating Button when Index 0 is not shown in the ListView. Most of the information in the web (including Stackoverflow) covers hiding the button when scrolling (direction) and not based on the index shown by ListView.
you can checklist null or not. I just add a demo code.
List<String> demoList = new List<>();
floatingActionButton: demoList != null ?
FloatingActionButton(
onPressed: () {
// Add your onPressed code here!
},
child: Icon(Icons.navigation),
backgroundColor: Colors.green,
)
:Text(''),
);
if the list has a value then it shows a floating button.
Use Visibility widget around FloatingActionButton. When the item shows, just call setState() method with visibility value.

How to update a CustomScrollView when returning from detail screen

I have a Scaffold that contains a CustomScrollView showing a list of items that the User has not tried (and another one that shows the items the User has tried).
Using the fantastic package flutter_sticky_header, I populate the CustomScrollView with a variety of SliverStickyHeaders and SliverLists to get something along the lines of:
Fruits
Apples >
Bananas >
Pears >
Vegetables
Broccoli >
Cabbage >
Potatoes >
The SliverLists are made up of some GestureDetector 'buttons' that take the user to a DetailScreen when tapped using something like:
onTap: () async {
bool result = await Navigator.push( *go to the DetailScreen* )
setState(() {
if (result) { *change the icon on the button* }
}
}
On the DetailScreen the User can indicate whether or not they have tried the item and when they Pop back to the first screen and the CustomScrollView, an icon on the button they pushed is updated to show a checkmark for items tried and a '>' for those they haven't.
Unfortunately, when the User Pops back to the list of items 'not tried', the item they just indicated having 'tried' is still there, and remains until the User navigates away and back.
What I want to do is update/refresh/rebuild the entire list so that when the User Pops back after changing an item from 'not tried' to 'tried' that item is no longer in the list of not tried items (and vice versa).
Basically, when the User Pops back, I can update the state of the specific widget that took them to the DetailScreen, but can't figure out how to update/refresh the state of the parent CustomScrollView widget up the chain.

Flutter toggle Radio widget

I'm using Radio widgets to set the user gender. These Radio button widgets are designed very well to handle the selection changes act accordingly, but I does not find a solution to somehow deselect one already selected option. I would like the gender radio group to be optional. But after user selects let's say female, he/she can change the selection to male, but can't deselect the female/male option. (So that none of the option is selected.)
There is only an onChanged property and it only changes if the gender changes. No such thing like onTap or something similar. So no matter if I check that gender if it's the same, onChanged won't be called.
For that reason I tried to use a GestureDetector which should solve this issue (with this I should be able to deselect the already selected option) but in case of radio widgets it does not work. I also tried to change it's behavior property but it did not help either.
Here is the function which I use to create gender radio option with a text in a Row.
Widget _buildRadioWithText(final genderChangeNotifier, final Gender genderParam, final String genderText) {
return Row(
children: <Widget>[
GestureDetector(
behavior: HitTestBehavior.translucent,
child: Radio<Gender>(
visualDensity: VisualDensity.compact,
value: genderParam,
groupValue: genderChangeNotifier.gender,
onChanged: (Gender gender) {
genderChangeNotifier.gender = gender;
print(gender.toString());
},
),
onTap: () {
if (genderChangeNotifier.gender == genderParam) {
genderChangeNotifier.gender = Gender.NA;
print("Not answered!");
}
},
),
GestureDetector(
onTap: () {
if (genderChangeNotifier.gender == genderParam) {
genderChangeNotifier.gender = Gender.NA;
print("Not answered!");
} else {
genderChangeNotifier.gender = genderParam;
print(genderParam.toString());
}
},
child: Text(
genderText,
style: TextStyle(
fontSize: _fontSize,
),
),
),
],
);
}
Function call:
_buildRadioWithText(genderChangeNotifier, Gender.FEMALE, "Female"),
_buildRadioWithText(genderChangeNotifier, Gender.MALE, "Male"),
genderChangeNotifieris just a provider to set and get the Gender value and notify listeners when a Gender is set.
final GenderNotifier genderChangeNotifier= Provider.of<GenderNotifier>(context);
GestureDetector's onTap works well when I tap on the Text widget. It selects then deselects the option just as I'd like to but in case of the Radio widget onTap is never called.
Any idea how to achieve the deselection when I tap/click on the Radio widget itself? And why the GestureDetector that wraps the Radio does not register the tap events?
The GestureDetector's onTap is not being called because the GestureDetector inside the Radio widget is taking priority. By default, when two GestureDetectors are competing for input, only one will "win". In this case, the winner is the one in the Radio. This article discusses "GestureArenas" and how you can allow both GestureDetectors to process input.
However, consider whether allowing the user to deselect the radio button is the correct solution. Radio buttons are designed not to be deselected once the user has selected an option. You might instead:
Offer a third, "I'd rather not say" option
Use toggleable buttons instead of a radio group
Use a dropdown menu instead of a radio group
See this answer for more info on the usability aspect of this.

CupertinoContextMenu previewBuilder or child widget not getting rebuilt while on fullscreen view, setState() called after dispose(): error when closed

I am using a CupertinoContextMenu widget to show some data from a Graphql query but I am having some issues with it on a particular use case.
The data updates fine while the CupertinoContextMenu is unpressed but when I press and hold it to activate the menu and have the child go fullscreen, the fields stop updating until I close the menu. Also it seems that the change only displays after the top item closes completely.
I am also having an issue every time I close the context menu with this action:
CupertinoContextMenuAction(
child: const Text('Toggle Network'),
onPressed: () {
runMutation(
toggleRunMutation,
optimisticResult: {
"action": {
"returning": [
{"portStatus": !item.portStatus}
]
}
},
);
Navigator.pop(context);
},
),
Executing the action and closing the context menu generates this error every time:
setState() called after dispose(): _CupertinoContextMenuState#97124(lifecycle state: defunct, not mounted, tickers: tracking 0 tickers)
Below a preview of the app.
Thanks a lot.