embraceitmobile / animated_tree_view

Animated TreeView based on AnimatedList allows building fully customizable Nodes that can be nested to infinite levels and children.
https://pub.dev/packages/animated_tree_view
MIT License
49 stars 23 forks source link

Tree is getting collapsed moving from one tab to another/screen #34

Open naveenbharadwaj19 opened 8 months ago

naveenbharadwaj19 commented 8 months ago

My tree expands for the first time, but when I move to another tab or page, it gets collapsed. I'm using GetX. I need my tree to remain expanded even if I move from one tab to another. How can I achieve this? I've attached code snippets and a video of the issue I'm facing.

class RelationTreeView extends StatefulWidget {
  @override
  State<RelationTreeView> createState() => _RelationTreeViewState();
}

class _RelationTreeViewState extends State<RelationTreeView> {
  final controller = Get.find<BookScanController>();

  @override
  Widget build(BuildContext context) {
    return GetBuilder<BookScanController>(
      builder: (_) => Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _heading(context),
          TreeView.simple(
            shrinkWrap: true,
            key: controller.globalKey,
            tree: controller.relationShipTree,
            showRootNode: false,
            expansionBehavior: ExpansionBehavior.scrollToLastChild,
            expansionIndicatorBuilder: (context, node) =>
                ChevronIndicator.upDown(
              tree: node,
              color: Theme.of(context).hintColor,
              padding: const EdgeInsets.all(15),
            ),
            indentation: Indentation(
              style: IndentStyle.squareJoint,
              thickness: 2.5,
              color: Theme.of(context).hintColor,
            ),
            builder: (context, node) => Container(
              margin: const EdgeInsets.only(top: 10, left: 10, right: 10),
              child: ListTile(
                leading: _.selectedPatientInfo == node.data
                    ? Icon(
                        Icons.check_circle_rounded,
                        size: 16,
                        color: Theme.of(context).indicatorColor,
                      )
                    : Icon(
                        Icons.check_circle_rounded,
                        size: 16,
                        color: Theme.of(context).disabledColor,
                      ),
                title: Text(
                  "${node.key}".toTitleCase(),
                  style: Theme.of(context).textTheme.bodySmall,
                ),
                subtitle: _patientCard(
                  node.data as Map<String, dynamic>?,
                  context,
                  node.level == 1 ? true : false,
                ),
                onTap: () {
                  controller.updateSelectedPatientInfo(
                    node.data as Map<String, dynamic>?,
                  );
                },
              ),
            ),
          ),
        ],
      ),
    );
  }

bookscancontroller.dart

class BookScanController extends GetxController{
   final globalKey = GlobalKey<TreeViewState>();

  TreeViewController? get tccontroller => globalKey.currentState?.controller;

   TreeNode relationShipTree = TreeNode.root();

   void _expandAllNodes() {
    tccontroller?.toggleExpansion(
      relationShipTree,
    );
  }

https://github.com/embraceitmobile/animated_tree_view/assets/63662884/f43e7a2f-47cb-4669-ad2a-928bf3d46f68

iaminhere22 commented 7 months ago

I have encountered the same problem.

hasimyerlikaya commented 6 months ago

Hi, Is there anyone to fix this? I need this feature so much.