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

unsupported operation infinity or nan toint #524

Closed
riccardopirani opened this issue Feb 20, 2020 · 16 comments
Closed

unsupported operation infinity or nan toint #524

riccardopirani opened this issue Feb 20, 2020 · 16 comments

Comments

@riccardopirani
Copy link

Hi I'm trying to implement the flutter_maps in my flutter application when I run the app but I have this error. what is it due to and how can i solve it?

Flutter Code:

import 'package:flutter_map/flutter_map.dart';
import 'package:Myapp/View/Cantieri/mediterranesn_diet_view.dart'
    show MediterranesnDietView;
import 'package:Myapp/View/Cantieri/title_view.dart' show TitleView;
import 'package:Myapp/View/Home_theme.dart';
import 'package:Myapp/View/MarcaTempo/meals_list_view.dart' show MealsListView;
import 'package:flutter/material.dart';
import 'package:latlong/latlong.dart';

class MyDiaryScreen extends StatefulWidget {
  const MyDiaryScreen({Key key, this.animationController}) : super(key: key);

  final AnimationController animationController;
  @override
  _MyDiaryScreenState createState() => _MyDiaryScreenState();
}

class _MyDiaryScreenState extends State<MyDiaryScreen>
    with TickerProviderStateMixin {
  Animation<double> topBarAnimation;

  List<Widget> listViews = <Widget>[];
  final ScrollController scrollController = ScrollController();
  double topBarOpacity = 0.0;

  @override
  void initState() {
    topBarAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
        CurvedAnimation(
            parent: widget.animationController,
            curve: Interval(0, 0.5, curve: Curves.fastOutSlowIn)));
    addAllListData();

    scrollController.addListener(() {
      if (scrollController.offset >= 24) {
        if (topBarOpacity != 1.0) {
          setState(() {
            topBarOpacity = 1.0;
          });
        }
      } else if (scrollController.offset <= 24 &&
          scrollController.offset >= 0) {
        if (topBarOpacity != scrollController.offset / 24) {
          setState(() {
            topBarOpacity = scrollController.offset / 24;
          });
        }
      } else if (scrollController.offset <= 0) {
        if (topBarOpacity != 0.0) {
          setState(() {
            topBarOpacity = 0.0;
          });
        }
      }
    });
    super.initState();
  }

  void addAllListData() {
    const int count = 9;

    //Prima view che comprende il titolo della Posizione
    listViews.add(
      TitleView(
        titleTxt: 'Posizione',
        subTxt: '',
        animation: Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation(
            parent: widget.animationController,
            curve:
                Interval((1 / count) * 0, 1.0, curve: Curves.fastOutSlowIn))),
        animationController: widget.animationController,
      ),
    );
    listViews.add(
      MediterranesnDietView(
        animation: Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation(
            parent: widget.animationController,
            curve:
                Interval((1 / count) * 1, 1.0, curve: Curves.fastOutSlowIn))),
        animationController: widget.animationController,
      ),
    );
    listViews.add(
      TitleView(
        titleTxt: 'Registrazione',
        subTxt: '',
        animation: Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation(
            parent: widget.animationController,
            curve:
                Interval((1 / count) * 2, 1.0, curve: Curves.fastOutSlowIn))),
        animationController: widget.animationController,
      ),
    );

    listViews.add(
      MealsListView(
        mainScreenAnimation: Tween<double>(begin: 0.0, end: 1.0).animate(
            CurvedAnimation(
                parent: widget.animationController,
                curve: Interval((1 / count) * 3, 1.0,
                    curve: Curves.fastOutSlowIn))),
        mainScreenAnimationController: widget.animationController,
      ),
    );

    listViews.add(
      TitleView(
        titleTxt: 'Mappa',
        subTxt: '',
        animation: Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation(
            parent: widget.animationController,
            curve:
                Interval((1 / count) * 2, 1.0, curve: Curves.fastOutSlowIn))),
        animationController: widget.animationController,
      ),
    );

    listViews.add(
      FlutterMap(
      options: new MapOptions(
        center: new LatLng(51.5, -0.09),
        zoom: 13.0,
      ),
      layers: [
        new TileLayerOptions(
            urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
            subdomains: ['a', 'b', 'c']),
        new MarkerLayerOptions(
          markers: [
            new Marker(
              width: 80.0,
              height: 80.0,
              point: new LatLng(51.5, -0.09),
              builder: (ctx) => new Container(
                child: new FlutterLogo(),
              ),
            ),
          ],
        ),
      ],
    ));
  }

  Future<bool> getData() async {
    await Future<dynamic>.delayed(const Duration(milliseconds: 50));
    return true;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: FintnessAppTheme.background,
      child: Scaffold(
        backgroundColor: Colors.transparent,
        body: Stack(
          children: <Widget>[
            //getMap(),
            getMainListViewUI(),
            getAppBarUI(),
            SizedBox(
              height: MediaQuery.of(context).padding.bottom,
            )
          ],
        ),
      ),
    );
  }

  Widget getMainListViewUI() {
    return FutureBuilder<bool>(
      future: getData(),
      builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
        if (!snapshot.hasData) {
          return const SizedBox();
        } else {
          return ListView.builder(
            controller: scrollController,
            padding: EdgeInsets.only(
              top: AppBar().preferredSize.height +
                  MediaQuery.of(context).padding.top +
                  24,
              bottom: 62 + MediaQuery.of(context).padding.bottom,
            ),
            itemCount: listViews.length,
            scrollDirection: Axis.vertical,
            itemBuilder: (BuildContext context, int index) {
              widget.animationController.forward();
              return listViews[index];
            },
          );
        }
      },
    );
  }

  //Widget che permette di recuperare la mappa per accedere alla posizione
  Widget getMap() {
    return new FlutterMap(
        options:
            new MapOptions(minZoom: 10.0, center: new LatLng(40.71, -74.00)),
        layers: [
          new TileLayerOptions(
              urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
              subdomains: ['a', 'b', 'c']),
          new MarkerLayerOptions(markers: [
            new Marker(
                width: 45.0,
                height: 45.0,
                point: new LatLng(40.73, -74.00),
                builder: (context) => new Container(
                      child: IconButton(
                          icon: Icon(Icons.accessibility),
                          onPressed: () {
                            print('Marker tapped!');
                          }),
                    ))
          ])
        ]);
  }

//Recupero della barra per la UI
  Widget getAppBarUI() {
    return Column(
      children: <Widget>[
        AnimatedBuilder(
          animation: widget.animationController,
          builder: (BuildContext context, Widget child) {
            return FadeTransition(
              opacity: topBarAnimation,
              child: Transform(
                transform: Matrix4.translationValues(
                    0.0, 30 * (1.0 - topBarAnimation.value), 0.0),
                child: Container(
                  decoration: BoxDecoration(
                    color: FintnessAppTheme.white.withOpacity(topBarOpacity),
                    borderRadius: const BorderRadius.only(
                      bottomLeft: Radius.circular(32.0),
                    ),
                    boxShadow: <BoxShadow>[
                      BoxShadow(
                          color: FintnessAppTheme.grey
                              .withOpacity(0.4 * topBarOpacity),
                          offset: const Offset(1.1, 1.1),
                          blurRadius: 10.0),
                    ],
                  ),
                  child: Column(
                    children: <Widget>[
                      SizedBox(
                        height: MediaQuery.of(context).padding.top,
                      ),
                      Padding(
                        padding: EdgeInsets.only(
                            left: 16,
                            right: 16,
                            top: 16 - 8.0 * topBarOpacity,
                            bottom: 12 - 8.0 * topBarOpacity),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: <Widget>[
                            Expanded(
                              child: Padding(
                                padding: const EdgeInsets.all(8.0),
                                child: Text(
                                  'Marcatempo',
                                  textAlign: TextAlign.left,
                                  style: TextStyle(
                                    fontFamily: FintnessAppTheme.fontName,
                                    fontWeight: FontWeight.w700,
                                    fontSize: 22 + 6 - 6 * topBarOpacity,
                                    letterSpacing: 1.2,
                                    color: FintnessAppTheme.darkerText,
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              ),
            );
          },
        )
      ],
    );
  }
}


@refo

This comment has been minimized.

@refo
Copy link

refo commented Feb 26, 2020

My bad.
Im my case, Container needed a height constraint.

#409 (comment)

@RaulUrtecho
Copy link

I have the same issue with TabBarView, one of my slides has a TextFiled that throw the error, when go the next slide sometimes happens others no, i don find the pattern yet.

@rachidev84
Copy link

Me too

I have the same issue with TabBarView, one of my slides has a TextFiled that throw the error, when go the next slide sometimes happens others no, i don find the pattern yet.

@rachidev84
Copy link

@RaulUrtecho
hello bro, I have same Error like yours, did you fixed it?

@ibrierley
Copy link
Collaborator

For anyone with a problem, a minimal test example would be useful for anyone to help.

@rachidev84
Copy link

rachidev84 commented Aug 20, 2020

@RaulUrtecho
the solution is to do this:
showCursor: false,

@korniychukalex
Copy link

I had the same error. I used PageView with 2 widget each of them contained text fileds. When I scrolled to the page (0 or 1) programatically (_pageController.animateToPage) I got this error.

Tehnical details:
After some time for debugging I found the problem with calculation "caretRect" code.
The problem was with method "localToGlobal", in my case I got empty matrix and as result division by zero (in "transformPoint" method).
But, why I got the empty matrix? And aswer was in "applyPaintTransform" method of "RenderSliverMultiBoxAdaptor" class:

_void applyPaintTransform(RenderBox child, Matrix4 transform) {
if (keepAliveBucket.containsKey(indexOf(child))) {
// It is possible that widgets under kept alive children want to paint
// themselves. For example, the Material widget tries to paint all
// InkFeatures under its subtree as long as they are not disposed. In
// such case, we give it a zero transform to prevent them from painting.
transform.setZero();
} else {
applyPaintTransformForBoxChild(child, transform);
}
}

So, in my case the problem was: I used 2 widgets (ScrollView pages) with "bool get wantKeepAlive => true;" to keep alive my pages, as I understood, it's not compatible with text fields for now.

Solution: don't use "wantKeepAlive" for yours pages with text fields.

I'm new in flutter and I hope it would be useful for someone.

@Mereep
Copy link

Mereep commented Oct 14, 2020

Maybe the map builder should fail early, i.e., it should throw an exception that the parent is not constrained in height.

(Wrapping FlutterMap into SizedBox(height: 300, child: FlutterMap(... fixed it for me.)

@RaulUrtecho
Copy link

@RaulUrtecho
the solution is to do this:
showCursor: false,

Sorry to reply a little bit late thanks indeed change this param avoid the exception. thanks man.

@DirkSimons
Copy link

Where does one put this showCursor: false, ??

@RaulUrtecho
Copy link

Where does one put this showCursor: false, ??

If I remember it is a TextField property.

@DirkSimons
Copy link

Well, i didn't go that way. It just needed a width and/or a height, so I wrapped it in a Container, gave it a width and a height to work with...Done:

Container(
  width:300,
  height:300,
  child: flutter_map(...)
)

@DirkSimons
Copy link

Well, i didn't go that way. It just needed a width or a height, so I wrapped it in a Container, gave it a width and a heigt to work with...Done:

Container(
  width:300,
  height:300,
  child: flutter_map(...)
)

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Mar 28, 2021
@github-actions
Copy link

github-actions bot commented Apr 2, 2021

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as completed Apr 2, 2021
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

8 participants