Navigation Menu

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

singleItem not working with multi-tags! #53

Closed
Maclaon opened this issue Jun 7, 2020 · 8 comments
Closed

singleItem not working with multi-tags! #53

Maclaon opened this issue Jun 7, 2020 · 8 comments

Comments

@Maclaon
Copy link

Maclaon commented Jun 7, 2020

          SelectTags(tags: _form),
          Divider(height: 1.0, indent: 0.0),
          SelectTags(tags: _type),
          Divider(height: 1.0, indent: 0.0),
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_tags/flutter_tags.dart';

class SelectTags extends StatefulWidget {
  final Map<String, String> tags;

  const SelectTags({Key key, this.tags}) : super(key: key);

  @override
  _SelectTagsState createState() => _SelectTagsState(tags);
}

class _SelectTagsState extends State<SelectTags> {
  final Map<String, String> tags;

  _SelectTagsState(this.tags);

  bool _symmetry = false;
  bool _startDirection = false;
  bool _horizontalScroll = true;
  int _column = 0;
  double _fontSize = 16;

  ItemTags _buildTagItem(Map<String,String> tags, index) {
    final item = tags.keys.elementAt(index);
    
    return ItemTags(
      key: Key(index.toString()),
      index: index,
      elevation: 0,
      title: item,
      active: false,
      singleItem: true,
      textColor: Colors.grey,
      textActiveColor: Colors.white,
      customData: item,
      color: Colors.white,
      activeColor: Colors.green[400],
      textScaleFactor: utf8.encode(item.substring(0, 1)).length > 2 ? 0.8 : 1,
      textStyle: TextStyle(fontSize: _fontSize),
      pressEnabled: true,
      onPressed: (_item) {

      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
          margin: EdgeInsets.all(5),
          child: Tags(
              symmetry: _symmetry,
              columns: _column,
              horizontalScroll: _horizontalScroll,
              verticalDirection: _startDirection
                  ? VerticalDirection.up
                  : VerticalDirection.down,
              textDirection:
                  _startDirection ? TextDirection.rtl : TextDirection.ltr,
              heightHorizontalScroll: 35 * (_fontSize / 14),
              itemCount: tags.entries.length,
              alignment: WrapAlignment.start,
              itemBuilder: (index) => _buildTagItem(tags, index)));
  }
}

when i click the tags in first SelectTags, it working, but not working in second SelectTags!

@Maclaon
Copy link
Author

Maclaon commented Jun 7, 2020

even i use two different widgets, it was still not working! it is weird!

@Dn-a
Copy link
Owner

Dn-a commented Jun 7, 2020

hi @Maclaon, have you tried to define a key? example:
Tags( key: Key( 'tags1'), ...)
Tags( key: Key('tags2'), ...)

@Maclaon
Copy link
Author

Maclaon commented Jun 8, 2020

hi @Maclaon, have you tried to define a key? example:
Tags( key: Key( 'tags1'), ...)
Tags( key: Key('tags2'), ...)

Oh!, sorry, my problem, the two widgets has same key! i will give it a try~

@Maclaon
Copy link
Author

Maclaon commented Jun 8, 2020

@Dn-a hi, when set different key in Tags it was still not working, and the second Tags error when i click on it is follow:

The following NoSuchMethodError was thrown while handling a gesture:
The getter 'active' was called on null.
Receiver: null
Tried calling: active

When the exception was thrown, this was the stack
#0      Object.noSuchMethod  (dart:core-patch/object_patch.dart:51:5)
#1      _ItemTagsState._singleItem.<anonymous closure> 
package:flutter_tags/src/item_tags.dart:438
#2      WhereIterator.moveNext  (dart:_internal/iterable.dart:442:13)
#3      WhereIterator.moveNext  (dart:_internal/iterable.dart:441:22)
#4      Iterable.forEach  (dart:core/iterable.dart:283:23)

when i scrolled the tags two the end, it works, but it still exists when i reentry that widget!

@Maclaon
Copy link
Author

Maclaon commented Jun 10, 2020

@Dn-a can u take a glance at this issue! i appreciate~

@Dn-a
Copy link
Owner

Dn-a commented Jun 10, 2020

@Maclaon I have to do some tests

@Maclaon
Copy link
Author

Maclaon commented Jun 13, 2020

@Dn-a hi~ buddy, i am looking forward to your answer!

@Maclaon
Copy link
Author

Maclaon commented Jun 16, 2020

i found another lib for my app. Thank u!

@Maclaon Maclaon closed this as completed Jun 16, 2020
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