How to Display value in Text widget in Flutter? - flutter

How can I display the value on Text Widget since I am using Getx
I trying to display the value of balance using as map but fail (and I guess it is not efficient)
the method I know is using index but cant work using Text widget (need builder)
where I can get index ??? or any advice to make it work and efficient since this is to show all value in the balance
This is a text widget I work but need an index
Here is the model, I want to show the value of balance in my Text widget

Obx(
() => ListView.builder(
itemCount: cashMain.transData.length,
itemBuilder: (context, index) {
return Text('${cashMain.transData[index].balance}')
},
)

Related

Can I get a logic/code for highlighting the desired value in the list view builder in flutter

[
Can I get a logic/code for highlighting just the selected value from this list view which is inside a container and it is scrollable also that the axis is set to Horizontal.
I have used a list view builder to align the same and also generated the list of numbers.
Please check the sample image of the widget attached.
Blockquote
]1
It's hard to tell you exactly how to do it without any code examples, and I'm also not sure what you mean by selected. Is that already decided before building the list, or is it decided when the user selects from the list?
If it is already decided, you can pass a value from the parent component that tells the list to highlight a certain value.
If a user is selecting the value to highlight, you can use a combination of setState and onTap with GestureDetector. Here's a potential rough skeleton:
int selectedIndex?;
ListView.builder(
itemCount: litems.length,
itemBuilder: (BuildContext ctx, int index) {
return GestureDetector(
onTap: () {
setState(() {
selectedIndex = index;
});
},
child: Container(
backgroundColor: selectedIndex == index ? highlightedColor : undefined;
child: {{child content}}
),
);
}
)

How i can make like this widget, in which when data grow up the last two item come down automatic

How can I make like this widget, in which when data grow up the last two item come down automatic and the size increase.
I don't want to use a fixed size
You are correct, you should not use a fixed size. You need to use a ListView
Assuming your items are in a List (e.g. of String to keep it simple):
List myInvoice = [];
myInvoice.add("Haircut Fee");
myInvoice.add("Beard Shave Fee");
//...
myInvoice.add("Tax");
Then, display in a ListView
ListView.builder(
itemCount: myInvoice.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(leading: myInvoice[index]);
}
);
If you get the logic, you can modify the List to hold objects more complex than a String, or use two lists.
More here

Dynamic ListView of stateful widgets not working

Dears,
it could be just a mistake of mine but ...it's driving me crazy ;)
I have a ListView inside my statefulwidget:
Expanded(
child: ListView.builder(
padding: EdgeInsets.all(10.0),
itemCount: searchableFoodList.length,
itemBuilder: (BuildContext context, int index) {
print('4 - SFL - ${searchableFoodList[index].id} - ${searchableFoodList[index].name}');
return
FoodItem(
id: searchableFoodList[index].id,
baseUnit: searchableFoodList[index].baseUnit,
baseUnitS: searchableFoodList[index].baseUnitS,
baseVal: searchableFoodList[index].baseVal,
baseValCal: searchableFoodList[index].baseValCal,
mediumVal: searchableFoodList[index].mediumVal,
mediumValCal: searchableFoodList[index].mediumValCal,
name: searchableFoodList[index].name,
note: searchableFoodList[index].note
);
},
),
searchableFoodList is modified (according user selection) inside a setState().
Let say that we have a 3 FoodItem(s), so my searchableFoodList is [FoodItem-1, FoodItem-2, FoodItem-3] and everything is working fine.
If I select a single item in my list, let say "FoodItem-2", the searchableFoodList becomes [FoodItem-2] and the list displayed contains (correctly) just one item but it is FoodItem-1.
Note that I inserted a print ...and it prints "FoodItem-2"
I guess that the problem is that it is considered the "original list" and it is changed only the length of the list but the list itself is not re-generated.
I have no more ideas ...any suggestions to solve this problem?
P.S.
FoodItem is stateful widget as well (an animated one). I did something similar with using stateless widget and I didn't have any problem

Is it possible to use ReorderableListView in a "wrapping" mode?

I would like the ReorderableListView not to take up the whole height which is given to it, but to be as tall as the item views that it contains.
I could make the list either flex and fill the whole height it is given, or put it in a SizedBox and have a fixed height.
I'd like to add an + Add list tile directly under the list items (similar to Google Keep on Android)
Thank you
You can try this:
Wrap your List with an Expanded widget.
Fetch the number of items in your list and return the Add List tile widget at the length-1 position of your list.
You can alter the size of your ListView in correlation to the number of items fetched from the list.
Expanded will help you alter the length dynamically.
eg:
Expanded(
child: new ListView.builder
(
itemCount: litems.length,
itemBuilder: (BuildContext ctxt, int Index) {
return new Text(litems[Index]);
if(length==length-1){
//**call your Add List tile widget here**
}
}
)
)

Why Flutter ListTile onTap seems cached?

I have two listview screen on my app. User can navigate between them using BottomNavigationBar control.
On listview.builder function, I return something like this
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
return ListTile(
title: Text('...'),
subtitle: Text('...'),
onTap: () {
...
}
)
});
I found onTap handler seems mixed between those 2 listviews.
When I open first list view, flutter serve the correct onTap,but when I switch to second listview, flutter still serving the first listview onTap.
Seems the onTap is cached by flutter (title & subtitle seems okay). Any idea?
Sample source code: https://github.com/jazarja/flutter_app
The problem is in your compararing transition values. Because you are first reversing the animation transition of current view.
In your botton_nav.dart, change this:
return aValue.compareTo(bValue);
to this:
return bValue.compareTo(aValue);
Yes the problem is that the animations haven't completed by the time the comparison is being done so the widget at the top of the stack is always 1 tab selection behind. You actually don't need to build a stack at all, just replace Center(child: _buildTransitionStack()) here with _navigationViews[_currentIndex].transition(_type, context) and it should work.