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

add this change to support null safety #7

Open
Marrawi1994 opened this issue Oct 28, 2021 · 1 comment
Open

add this change to support null safety #7

Marrawi1994 opened this issue Oct 28, 2021 · 1 comment

Comments

@Marrawi1994
Copy link

Hi Guys ...
For anyone need to use this library with null safety support .. follow these steps :

First : copy files from root directory -> lib -> src and paste in your project

Secound : Go to tree_view.dart

change code in line 18 to this

 const TreeView({
    Key? key,  // add this line
    @required this.data,
    this.titleKey = 'title',
    this.leadingKey = 'leading',
    this.expanedKey = 'expaned',
    this.childrenKey = 'children',
    this.offsetLeft = 24.0,
    this.titleOnTap,
    this.leadingOnTap,
    this.trailingOnTap,
  }) : super(key: key);  // replace with this line

third : Go to tree_node.dart

change code in line 17 to this :

 const TreeNode({ 
    Key? key, // add this line
    this.level = 0,
    this.expaned = false, 
    this.offsetLeft = 24.0,
    this.children = const [],
    this.title = const Text('Title'),
    this.leading = const IconButton(
      icon: Icon(Icons.star_border),
      iconSize: 16,
      onPressed: null,
    ),
    this.trailing = const IconButton(
      icon: Icon(Icons.expand_more),
      iconSize: 16,
      onPressed: null,
    ),
    this.titleOnTap,
    this.leadingOnTap,
    this.trailingOnTap,
  }); : super(key: key); // replace with this line

in line 50 add this:

  @override // add this line
  initState() {
    _isExpaned = widget.expaned;
    _rotationController = AnimationController(
      duration: const Duration(milliseconds: 300),
      vsync: this,
    );
    super.initState();
  }

in line 90 and line 102 :

const SizedBox(width: 6.0), // add const
Expanded(
  child: GestureDetector(
    onTap: () {
      if (widget.titleOnTap != null &&
          widget.titleOnTap is Function) {
        widget.titleOnTap();
      }
    },
    child: widget.title ?? Container(),
  ),
),
const SizedBox(width: 6.0), // add const
Visibility(
  visible: children.isNotEmpty, // replace with isNotEmpty

in line 136 :

Visibility(
  visible: children.isNotEmpty && _isExpaned, // replace with isNotEmpty
  child: Padding(
    padding: EdgeInsets.only(left: level + 1 * offsetLeft),
    child: Column(
      children: widget.children,
      crossAxisAlignment: CrossAxisAlignment.start,
    ),
  ),
),

That's all 👍 👍 👍

@xrr2016
Copy link
Owner

xrr2016 commented Mar 23, 2022

It's null safety now!

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

2 participants