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

Exception caught by rendering library #363

Closed
ashutosh840 opened this issue May 31, 2020 · 6 comments
Closed

Exception caught by rendering library #363

ashutosh840 opened this issue May 31, 2020 · 6 comments

Comments

@ashutosh840
Copy link

ashutosh840 commented May 31, 2020

`
The following assertion was thrown during paint():
Offset argument contained a NaN value.
dart:ui/painting.dart':
Failed assertion: line 39: ''

The relevant error-causing widget was:
PieChart file:///D:/flutterProjects/moneymanager/lib/stats.dart:72:14
When the exception was thrown, this was the stack:
#2 _offsetIsValid (dart:ui/painting.dart:39:10)
#3 Canvas.drawLine (dart:ui/painting.dart:3649:12)
#4 PieChartPainter._removeSectionsSpace. (package:fl_chart/src/chart/pie_chart/pie_chart_painter.dart:147:14)
#5 ListMapView.forEach (dart:_internal/list.dart:244:8)
#6 PieChartPainter._removeSectionsSpace (package:fl_chart/src/chart/pie_chart/pie_chart_painter.dart:117:27)
...
The following RenderObject was being processed when the exception was fired: RenderCustomPaint#43a5c relayoutBoundary=up3
... parentData: (can use size)
... constraints: BoxConstraints(0.0<=w<=360.0, 0.0<=h<=Infinity)
... size: Size(252.0, 252.0)
RenderObject: RenderCustomPaint#43a5c relayoutBoundary=up3
parentData: (can use size)
constraints: BoxConstraints(0.0<=w<=360.0, 0.0<=h<=Infinity)
size: Size(252.0, 252.0)
`

This is the exception I am getting every time I run the code

@imaNNeo
Copy link
Owner

imaNNeo commented Jun 2, 2020

Please give us a reproducible code.

@ashutosh840
Copy link
Author

ashutosh840 commented Jun 2, 2020

Actually I used another library and updated the code a lot so it is difficult for me to give the code but let me explain the entire situation

So I was using moor and I made a function to get a Future<List<... >> and now in FutureBuilder I tried
`

return FutureBuilder(
    future: dao.getAllAccounts(),
    builder: (context, AsyncSnapshot<List<Account>> snapshot) {
  if(snapshot.connectionState==ConnectionState.done){

    final accounts = snapshot.data ?? List();
    if (accounts == null) {

      return Text('No Accounts Yet');
    } else {
      Provider.of<Amount>(context,listen: false).add(Calculate(accounts, Type.SNACKS), Calculate(accounts, Type.ENTERTAINMENT),
          Calculate(accounts, Type.STATIONARY), Calculate(accounts, Type.OTHERS));

      


      return  PieChart(
        //...  PieChart data 
      );
    }

  }


}

`

`
class Amount extends ChangeNotifier {

  double snack_amount=0.0;
  double entertainment_amount=0.0;
  double stationary_amount=0.0;
  double  others_amount=0.0;

  void add(double snack,double entertainment,double stationary, double others){
    snack_amount=snack;
    entertainment_amount=entertainment;
    stationary_amount=stationary;
    others_amount=others;
    notifyListeners();
  }
}
`

Now in this you could see I used changeNotfiers , and by the way that calculate method returns a double now I provided the respective values to PieChartSectionData like this
Provider.of<Amount>(context,listen: false).snack_amount

@ashutosh840
Copy link
Author

I hope I gave you an approx idea of how I did this thing and let me know if anything else you want to know

@imaNNeo
Copy link
Owner

imaNNeo commented Jun 2, 2020

It doesn't help me,
please narrow down it and find a reproducible code, or let it be open until someone provides a reproducible code.
Thanks!

@aitrenI
Copy link

aitrenI commented Jul 15, 2020

same issue happens with me when I make:

    centerSpaceRadius: double.infinity,

while any finite value doesn't throw this exception

@imaNNeo imaNNeo closed this as completed Jul 26, 2020
@nck974
Copy link

nck974 commented Nov 26, 2022

Hello, I think I had the same problem using drift. The problem is not related to the library but to how the FutureBuilder is used.

The future: dao.getAllAccounts(), in the example provided by @ashutosh840 will be called each time a setState from the library is called, and as the FutureBuilder will dispose the children it will crash with an error SetState() called after dispose.

Instead the future property should be mapped to a variable that is initialized on init:

class _MyWidgetState extends State<MyWidget> {
  late Future<List<String>> myFutureVariable;

  Future<List<String>> _getStringValueFromDb() async {
    return await db.getSomething();
  }

  @override
  void initState() {
    super.initState();
    myFutureVariable= _getStringValueFromDb();
  }
...
FutureBuilder<List<String>>(
   future: myFutureVariable,
...

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

No branches or pull requests

4 participants