The following code has a list from 1 to 100, on top has three buttons to change the order of the list (increasing, decreasing or shuffle).
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
class SamplePage extends StatefulWidget {
SamplePage({Key key}) : super(key: key);
@override
_SamplePageState createState() => _SamplePageState();
}
class _SamplePageState extends State<SamplePage> {
_SamplePageState();
final _list = new List<int>.generate(100, (i) => i + 1);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
TextButton(
onPressed: () => setState(() {
_list.sort((a, b) => a.compareTo(b));
}),
child: Text(
"Sort increasing",
),
),
TextButton(
onPressed: () => setState(() {
_list.sort((a, b) => b.compareTo(a));
}),
child: Text(
"Sort decreasing",
),
),
TextButton(
onPressed: () => setState(() {
_list.shuffle();
}),
child: Text(
"Shuffle",
),
),
Expanded(
child: ListView.builder(
itemCount: _list.length,
itemBuilder: (context, index) => Text(
'${_list[index]}',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16.0,
),
),
),
),
],
),
);
}
}
Everything works but as I'm new to flutter, I'm wondering if it is possible to make the items of the list change with animation.
On android world, we can do it through the setHasStableIds in a RecyclerView adapter, I imagine the approach on flutter maybe be different, but I guess it is possible to achieve the same result, I would like to know how.
Edited
I'm adding here a gif of how items change position animated when you are using a native recyclerview, this animated change of positions is what I'm looking for.
