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

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

Related

different text direction for different lines for a poem text in flutter

image1 , image2 I want to fetch text from Json file and show the text in different text direction for different lines
Trying to build with a listview.builder Is it possible
Good, as it show up in the image the text seems to be always alternate, so you can apply a validation to alternate with the index. Try change the textDirection detecting if the index is odd or even.
ListView.builder(
AlwaysScrollableScrollPhysics()),
itemCount: this.yourValue.length,
itemBuilder: (BuildContext ctx, int index){
return YourBuildList(this.yourValue[index],
index.floor().isEven ? true : false); //here you can handle. If is even is TextAlign.start. If it is odd is TextAlign.end or vice versa
}),
As i said before, with a code example the anwers could be better, greetings.

How to make flutter listview show millions of items

I'm tring to write a log viewer application with flutter.
I've learn that ListView.builder could handle larget number, even infinite number of items.
for example:
const mockLines = [
'this is a short line that will display in one line',
'this is a long line that will display in multiple lines, let us see how long it will be ?',
];
Widget _buildLogView() {
return ListView.builder(
itemCount: 1000,
itemBuilder: (context, index) {
final line = mockLines[index % mockLines.length];
return Text('$index: $line');
}
);
}
which works good, text got wrapped when it's too long.
But scrolling got very slow, and memory got blow when I set itemCount to 1000000.
Tried itemExtent:
Widget _buildLogView() {
return ListView.builder(
itemCount: 1000000,
itemExtent: 20
itemBuilder: (context, index) {
final line = mockLines[index % mockLines.length];
return Text('$index: $line');
}
);
}
Problem solved.
However, text won't wrap anymore, it just got truncated.
It seems that there's no way for me to create a listview can handle millions of lines when keeping the 'wrap' behavior.
Am I miss something, or just a limitation of flutter?
===============
A release build, draging scrollbar to 1/3 with itemCount = 1000000
memory keep crimbing up (would finally eat all)
same on windows:

How to Display value in Text widget in 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}')
},
)

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**
}
}
)
)

How to use detect changes in elements of an array using provider?

I started developing my first app with flutter and I have some questions.
I have a screen that contains a Horizontal ListView where each item represents a month and occupy the entire screen. Each item is another list of itens. It's basically a list showing expenses for every month. I'm controlling state using Provider, and I'm having trouble to detect changes in a month. For example, I'm in january, but I added an expense in february, so the february item must detect the change and rewrite. I haven't been able to do it so far. Here is the screenshots of the app:
I have a provider that has an array of "Periods". And a "Period" is a class that represents a month, and contains an array of expenses.
I guess I'm not organising my data the right away, I'd appreciate if someone could point me in the right direction.
EDIT:
So, I watched this video here: https://www.youtube.com/watch?v=d_m5csmrf7I, and that helped me a little at least on how to detect changes in nested providers. I basically did this:
Widget build(BuildContext context) {
...
final size = MediaQuery.of(context).size;
final financeiro = Provider.of<Financeiro>(context);
return ImprovedListView.builder(
controller: _listController,
scrollDirection: Axis.horizontal,
itemCount: financeiro.periodos.length,
itemSize: size.width,
physics: const NeverScrollableScrollPhysics(),
initialScrollOffset: financeiro.indexMesAtual * size.width,
itemBuilder: (ctx, index) {
final periodo = financeiro.periodos[index]; //get a piece of the list and pass to another change notifier provider
return ChangeNotifierProvider<Periodo>.value(
value: periodo,
child: PeriodoFinanceiro(
key: ValueKey('${periodo.ano}${periodo.mes}'),
index: index,
scrollTo: scrollTo,
carregarDadosIniciais: carregarDadosIniciais,
excluirLancamento: excluirLancamento,
),
);
};
}
Now I just have to figure out how to better control the scrolloffset of the list when its re-rendered.
Thanks