Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
naveenbharadwaj19 opened this issue Nov 18, 2023 · 2 comments
Open

Comments

@naveenbharadwaj19
Copy link

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,
    );
  }
bandicam.2023-11-18.17-23-25-858.mp4
@iaminhere22
Copy link

I have encountered the same problem.

@hasimyerlikaya
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants