This is the my treeview page Scaffold code sample. I used Animated tree view class
import 'package:animated_tree_view/animated_tree_view.dart';
// Widget build
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: Text(widget.title),
),
body: CustomScrollView(
controller: scrollController,
slivers: [
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.only(
top: 12.0, left: 12, right: 30, bottom: 12),
child: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 200,
height: 40,
child: ElevatedButton(
child: const Text("Add main activity"),
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).primaryColor,
textStyle: const TextStyle(color: Colors.white),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5))),
onPressed: () {
// simpleTree.add(TreeNode());
Navigator.of(context)
.push(MaterialPageRoute(
builder: (context) => const ActivityAdd(
title: 'Add Activity', selfId: 'root')))
.then((val) => {
debugPrint(val),
val ? _getRequests() : null
});
},
),
),
)),
),
SliverTreeView.simple(
tree: simpleTree,
expansionBehavior: ExpansionBehavior.collapseOthers,
showRootNode: false,
key: _simpleTreeKey,
scrollController: scrollController,
builder: (context, node) => Card(
child: node.isRoot
? buildRootItem(node)
: buildListItem(node)),
),
],
));
}
If you have any experience animated tree view with firebase data. Finally I want to auto update when user add a new tree node to database. I find some ways to display tree view but it is not work to real time. Please help me.
I solved this problem myself.
Final code as follows
It was working well now.