2

my flutter app is crashing after I press the back arrow on the phone.

how to make the error happen:

1 - this button sends to a route that uses google maps.

ElevatedButton(
            child: Text('Profesional'),
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(builder: (context) => MyApp2()),
              );
            },
          ), 

2-

This shows a live map that tracks the position of your phone.

import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:flutter/material.dart';
import 'package:location/location.dart';


class MyApp2 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  LatLng _initialcameraposition = LatLng(20.5937, 78.9629);
  GoogleMapController _controller;
  Location _location = Location();

  void _onMapCreated(GoogleMapController _cntlr) {
    _controller = _cntlr;
    _location.onLocationChanged.listen((l) {
      _controller.animateCamera(
        CameraUpdate.newCameraPosition(
          CameraPosition(target: LatLng(l.latitude, l.longitude), zoom: 15),
        ),
      );
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        height: MediaQuery.of(context).size.height,
        width: MediaQuery.of(context).size.width,
        child: Stack(
          children: [
            GoogleMap(
              initialCameraPosition:
                  CameraPosition(target: _initialcameraposition),
              mapType: MapType.normal,
              onMapCreated: _onMapCreated,
              myLocationEnabled: true,
            ),
          ],
        ),
      ),
    );
  }
}

3 -

When I press the back button of the phone, the app crashes and shows me this. which is inside a platform_channel.dart file that I believe is created automatically.

BinaryMessenger get binaryMessenger => _binaryMessenger ?? ServicesBinding.instance!.defaultBinaryMessenger;
  final BinaryMessenger? _binaryMessenger;

  @optionalTypeArgs
  Future<T?> _invokeMethod<T>(String method, { required bool missingOk, dynamic arguments }) async {
    assert(method != null);
    final ByteData? result = await binaryMessenger.send(
      name,
      codec.encodeMethodCall(MethodCall(method, arguments)),
    );
    if (result == null) {
      if (missingOk) {
        return null;
      }
      

    *throw MissingPluginException('No implementation found for method $method on channel $name');*

    }
    return codec.decodeEnvelope(result) as T?;
  }

the program (Visual studio ) highlights the line that I put between * *.

Nelson Jr.
  • 1,189
  • 8
  • 11
  • Why does the Navigator go to MyApp2 (which contains a new MaterialApp) instead of directly to MyHomePage? – Zac May 05 '21 at 23:14
  • to be honest im not sure, I got that code from an example in a tutorial. I tried using MyHomePage to see if it could have any effect but its the same. – Martin Pizarro May 06 '21 at 00:09
  • Hmmmm. Would you be able to show the rest of the error log? – Zac May 06 '21 at 01:00
  • it doesnt even show something as an error, the app just freezes completely and then highlights that part of the code that I showed on point 3. – Martin Pizarro May 06 '21 at 03:48
  • Check if any of the answers here help https://stackoverflow.com/questions/50687801/flutter-unhandled-exception-missingpluginexceptionno-implementation-found-for – Zac May 06 '21 at 18:27
  • didnt find any help there – Martin Pizarro May 11 '21 at 01:18
  • Are you testing this on a physical phone or an emulator? And which OS is it (with version) – Zac May 11 '21 at 16:18
  • I tried testing it on my phone and it works just fine, but with the emulator (PIXEL 3 API 30) it just gives that error. Should I be using my phone as the main test method? is it more reliable? – Martin Pizarro May 14 '21 at 19:38
  • Actually I tested it again and it just takes longer to crash but it does crash eventually. – Martin Pizarro May 17 '21 at 12:49

0 Answers0