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

isTap() method not working properly? #52

Open
JoseDelPino opened this issue Dec 15, 2019 · 4 comments
Open

isTap() method not working properly? #52

JoseDelPino opened this issue Dec 15, 2019 · 4 comments
Labels
bug Something isn't working

Comments

@JoseDelPino
Copy link

It seems to be triggered only when a long press is made over a Parent. Additionally, it is triggered twice in that case (at least for me).

@ReinBentdal ReinBentdal added the bug Something isn't working label Dec 15, 2019
@ReinBentdal
Copy link
Owner

will look into it in the next couple days. Could you please provide your code where the error occurs?

@JoseDelPino
Copy link
Author

Here you have it, thanks for the quick response :)

`import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:visualicer/affiliation.dart';
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:visualicer/globals.dart';
import 'package:division/division.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'VISUALICE'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

final String title;

@OverRide
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State {

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: ListView(
children: [
SectionItem(Icons.work, hex('#e3366a'), 'Afiliación', 'Datos de afiliación a la S.S.', 'affiliation'),
SectionItem(Icons.people, hex('#34b7eb'), 'Matrimonios', 'Datos de matrimonios', 'marriage'),
SectionItem(Icons.nature_people, hex('#72db80'), 'Población', 'Datos de población', 'population'),
],
),
),
);
}
}

class SectionItem extends StatefulWidget {
SectionItem(this.icon, this.iconBgColor, this.title, this.description, this.navigator);

final IconData icon;
final Color iconBgColor;
final String title;
final String description;
final String navigator;

@OverRide
_SectionItemState createState() => _SectionItemState();
}

class _SectionItemState extends State {
bool pressed = false;

@OverRide
Widget build(BuildContext context) {
return Parent(
style: settingsItemStyle(pressed),

  gesture: Gestures()
    ..isTap((isTapped) => setState(() {
      print("The item was tapped");
      pressed = isTapped;
      _goToSection(widget.navigator);
    })),

  child: Row(
    children: <Widget>[
      Parent(
        style: settingsItemIconStyle(widget.iconBgColor),
        child: Icon(widget.icon, color: Colors.white, size: 20),
      ),
      SizedBox(width: 10),
      Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Txt(widget.title, style: itemTitleTextStyle),
          SizedBox(height: 5),
          Txt(widget.description, style: itemDescriptionTextStyle),
        ],
      )
    ],
  ),
);

}

void _goToSection(String navigator) async {

if(navigator == 'affiliation'){

  var data = [];

  affiliations = await Firestore.instance
      .collection("Afiliacion")
      .getDocuments();
  print(affiliations.documents.length);
  affiliations.documents.forEach((doc) => data.add(
      new MonthlyAffiliation(
          doc.documentID.toString(), doc.data["Soria"]["total"], Colors.purpleAccent)));

  List<charts.Series<dynamic, String>> series = [
    new charts.Series(
      id: 'AfiliacionPorMes',
      colorFn: (afiliacion, _) => afiliacion.color,
      domainFn: (afiliacion, _) => afiliacion.month,
      measureFn: (afiliacion, _) => afiliacion.people,
      data: data,
    )];

  Navigator.push(
    context,
    MaterialPageRoute(
        builder: (context) =>
            StatefulAffiliation(series)),
  );

}

}

final settingsItemStyle = (pressed) => ParentStyle()
..elevation(pressed ? 0 : 50, color: Colors.grey)
..scale(pressed ? 0.95 : 1.0)
..alignmentContent.center()
..height(70)
..margin(vertical: 10)
..borderRadius(all: 15)
..background.hex('#ffffff')
..ripple(true)
..animate(150, Curves.easeOut);

final settingsItemIconStyle = (Color color) => ParentStyle()
..background.color(color)
..margin(left: 15)
..padding(all: 12)
..borderRadius(all: 30);

final TxtStyle itemTitleTextStyle = TxtStyle()
..bold()
..fontSize(16);

final TxtStyle itemDescriptionTextStyle = TxtStyle()
..textColor(Colors.black26)
..bold()
..fontSize(12);
}
`

@ReinBentdal
Copy link
Owner

Not entirely sure what the problem is but i think the problem is just an illusion when testing on a emulator. What feels like a long press on a emulator can be a normal tap on a real device.
I would also suggest changing the itTap function to:

..isTap((isTapped) {
  print("The item was tapped $isTapped");
  _goToSection(widget.navigator);
  setState(() => pressed = isTapped);
}

When the setState function is called the widget will rerender. Therefore everthing you want to do should be done before you call setState.

Let me know if this helped. I would also suggest testing it on a real device if you havent yet to see if there is a problem in a "real" scenario.

@JoseDelPino
Copy link
Author

The problem still persists, even on a real device. _goToSection(widget.navigator); is executed TWICE only when a long press is release.

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants