Google Maps and Websocket Flutter

Asked

Viewed 158 times

1

All right, come on... I’m developing an application using flutter (I’m new to the Dart language), so I need my application to update the markers of maps periodically along with Websocket, but when it updates my maps stops working, leaving the screen all white...

@override

void initState() {
    super.initState();
    checkUserLogged();
    _getAddrs();
    wsConnect();
  }

  @override
  void dispose() {
    channel.sink.close();
    super.dispose();
  }

  wsConnect() async {
    channel = await IOWebSocketChannel.connect('ws://31.220.54.205:3002');
    channel.stream.listen((message) {
      channel.sink.add(message);
    });
  }




StreamBuilder(
                stream: channel.stream,
                builder: (BuildContext context, AsyncSnapshot snapshot) {
                  if (snapshot.hasData) {
                    var jsonResult = json.decode(snapshot.data);

                    for (var end in jsonResult) {
                      _markers.add(
                        Marker(
                          markerId: MarkerId((end['truck_name'].length > 0 ? end['truck_name'] : 'Caminhão de Lixo')),
                          draggable: false,
                          icon: BitmapDescriptor.fromAsset("assets/pngs/caminhaozinho.png"),
                          position: LatLng(double.parse(end['truck_lat']), double.parse(end['truck_lng'])),
                        ),
                      );
                    }

                    return Container(
                      height: MediaQuery.of(context).size.height,
                      width: MediaQuery.of(context).size.width,
                      child: GoogleMap(
                        myLocationEnabled: true,
                        myLocationButtonEnabled: false,
                        minMaxZoomPreference: MinMaxZoomPreference(14, 17),
                        onMapCreated: _onMapCreated,
                        initialCameraPosition: CameraPosition(
                          target: LatLng(lat, long),
                          zoom: 17.0,
                        ),
                        compassEnabled: true,
                        markers: Set.from(_markers),
                      ),
                    );
                  } else {
                    return MaterialApp(
                      home: Scaffold(
                        body: Container(
                          child: Center(
                            child: CircularProgressIndicator(
                              backgroundColor: Colors.green
                            ),
                          ),
                        ),
                      ),
                    );
                  }
                }
              ),

When I run the application on my emulator I get the following log:

I/flutter ( 6163): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter ( 6163): The following Stateerror was thrown building Mediaquery(Mediaquerydata(size: Size(411.4, 683.4), I/flutter ( 6163): devicePixelRatio: 2.6, textScaleFactor: 1.0, platformBrightness: Brightness.light, padding: I/flutter ( 6163): Edgeinsets(0.0, 24.0, 0.0, 0.0), viewPadding: Edgeinsets(0.0, 24.0, 0.0, 0.0), viewInsets: I/flutter ( 6163): Edgeinsets.zero, alwaysUse24HourFormat: false, accessibleNavigation: false, disableAnimations: I/flutter ( 6163): false, invertColors: false, boldText: false)): I/flutter ( 6163): Bad state: Stream has already been listened to. I/flutter ( 6163): I/flutter ( 6163): When the Exception was thrown, this was the stack: I/flutter ( 6163): #3 _Completerstream.Listen (package:async/src/stream_completer.Dart:133:31) I/flutter ( 6163): #7 _Streambuilderbasestate. _subscribe (package:flutter/src/widgets/async.Dart:135:37) I/flutter ( 6163): #8 _Streambuilderbasestate.initState (package:flutter/src/widgets/async.Dart:109:5) I/flutter ( 6163): #9 Statefulelement. _firstBuild (package:flutter/src/widgets/framework.Dart:4033:58) I/flutter ( 6163): #10 Componentelement.mount (package:flutter/src/widgets/framework.Dart:3902:5) I/flutter ( 6163): #11 Element.inflateWidget (package:flutter/src/widgets/framework.Dart:3084:14) I/flutter ( 6163): #12 Multichildrenderobjectelement.mount (package:flutter/src/widgets/framework.Dart:5198:32) I/flutter ( 6163): #13 Element.inflateWidget (package:flutter/src/widgets/framework.Dart:3084:14) I/flutter ( 6163): #14 Element.updateChild (package:flutter/src/widgets/framework.Dart:2887:12) I/flutter ( 6163): #15 Componentelement.performRebuild (package:flutter/src/widgets/framework.Dart:3935:16) I/flutter ( 6163): #16 Element.rebuild (package:flutter/src/widgets/framework.Dart:3721:5) I/flutter ( 6163): #17 Componentelement. _firstBuild (package:flutter/src/widgets/framework.Dart:3907:5) I/flutter ( 6163): #18 Componentelement.mount (package:flutter/src/widgets/framework.Dart:3902:5) I/flutter ( 6163): #19 Element.inflateWidget (package:flutter/src/widgets/framework.Dart:3084:14) I/flutter ( 6163): #20 Element.updateChild (package:flutter/src/widgets/framework.Dart:2887:12) I/flutter ( 6163): #21 Componentelement.performRebuild (package:flutter/src/widgets/framework.Dart:3935:16) I/flutter ( 6163): #22 Element.rebuild (package:flutter/src/widgets/framework.Dart:3721:5) I/flutter ( 6163): #23 Componentelement. _firstBuild (package:flutter/src/widgets/framework.Dart:3907:5) I/flutter ( 6163): #24 Componentelement.mount (package:flutter/src/widgets/framework.Dart:3902:5) I/flutter ( 6163): #25 Parentdataelement.mount (package:flutter/src/widgets/framework.Dart:4279:11) I/flutter ( 6163): #26 Element.inflateWidget (package:flutter/src/widgets/framework.Dart:3084:14) I/flutter ( 6163): #27 Multichildrenderobjectelement.mount (package:flutter/src/widgets/framework.Dart:5198:32) I/flutter ( 6163): #28 Element.inflateWidget (package:flutter/src/widgets/framework.Dart:3084:14) I/flutter ( 6163): #29 Element.updateChild (package:flutter/src/widgets/framework.Dart:2887:12) I/flutter ( 6163): #30 Componentelement.performRebuild (package:flutter/src/widgets/framework.Dart:3935:16) I/flutter ( 6163): #31 Element.rebuild (package:flutter/src/widgets/framework.Dart:3721:5) I/flutter ( 6163): #32 Componentelement. _firstBuild (package:flutter/src/widgets/framework.Dart:3907:5) I/flutter ( 6163): #33 Statefulelement. _firstBuild (package:flutter/src/widgets/framework.Dart:4053:11) I/flutter ( 6163): #34 Componentelement.mount (package:flutter/src/widgets/framework.Dart:3902:5) I/flutter ( 6163): #35 Element.inflateWidget (package:flutter/src/widgets/framework.Dart:3084:14) I/flutter ( 6163): #36 Element.updateChild (package:flutter/src/widgets/framework.Dart:2887:12) I/flutter ( 6163): #37 Componentelement.performRebuild (package:flutter/src/widgets/framework.Dart:3935:16) I/flutter ( 6163): #38 Element.rebuild (package:flutter/src/widgets/framework.Dart:3721:5) I/flutter ( 6163): #39 Componentelement. _firstBuild (package:flutter/src/widgets/framework.Dart:3907:5) I/flutter ( 6163): #40 Componentelement.mount (package:flutter/src/widgets/framework.Dart:3902:5) I/flutter ( 6163): #41 Element.inflateWidget (package:flutter/src/widgets/framework.Dart:3084:14) I/flutter ( 6163): #42 Element.updateChild (package:flutter/src/widgets/framework.Dart:2887:12) I/flutter ( 6163): #43 Componentelement.performRebuild (package:flutter/src/widgets/framework.Dart:3935:16) I/flutter ( 6163): #44 Element.rebuild (package:flutter/src/widgets/framework.Dart:3721:5) I/flutter ( 6163): #45 Componentelement. _firstBuild (package:flutter/src/widgets/framework.Dart:3907:5) I/flutter ( 6163): #46 Statefulelement. _firstBuild (package:flutter/src/widgets/framework.Dart:4053:11) I/flutter ( 6163): #47 Componentelement.mount (!)

Someone would know how to help me?

1 answer

1

Screen state emulator images are important !!!

Problem is on the interface, this giving media.query error and overflow, why the screen is white (as you described).

Try to review its interface and measurements

If the problem is in the packages

flutter clean
flutter run

Browser other questions tagged

You are not signed in. Login or sign up in order to post.