flutter-mapbox-gl / maps

A Mapbox GL flutter package for creating custom maps
Other
1.03k stars 498 forks source link

Widget test No implementation found for method create on channel flutter/platform_views #1386

Closed Andre-Coelhoo closed 7 months ago

Andre-Coelhoo commented 9 months ago

Hello everyone i'm having this error when running widget tests

The following MissingPluginException was thrown running a test:
MissingPluginException(No implementation found for method create on channel flutter/platform_views)

When the exception was thrown, this was the stack:
#0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:313:7)
<asynchronous suspension>
<asynchronous suspension>

the state is the correct, the mock data is also correct. Can anyone push me to the correct path. what im doing wrong?

void main() {
  final TestWidgetsFlutterBinding binding =
      TestWidgetsFlutterBinding.ensureInitialized();

  group('scan tagOnboarding screen Golden Test', () {
    late DashboardCubit dashboardCubit;
    late MapboxMapCubit mapboxMapCubit;
    late SessionCubit sessionCubit;
    late StreamController<Customer> customerStream;
    late StreamController<Site> siteStream;
    late StreamController<bool> resetStream;
    late StreamController<bool> liveMapStream;

    tearDown(() {
      customerStream.close();
      siteStream.close();
      resetStream.close();
      dashboardCubit.close();
      liveMapStream.close();
    });
    for (GoldenTheme theme in GoldenTheme.values) {
      for (GoldenScale scale in GoldenScale.values) {
        for (PhysicalSize physicalSizeDevices in PhysicalSize.values) {
          testWidgets('dashboard screen Golden Test ' ,(WidgetTester tester) async {
            // change screen size and pixel density ratio
            binding.window.physicalSizeTestValue =
                physicalSizeDevices.physicalSizes;
            binding.window.devicePixelRatioTestValue = 1.0;
            await loadAppFonts();
            customerStream = StreamController<Customer>();
            siteStream = StreamController<Site>();
            resetStream = StreamController<bool>();
            liveMapStream = StreamController<bool>();
            sessionCubit = MockSessionCubit();
            MockGlobalOptionsRepository globalOptionsRepository =
                MockGlobalOptionsRepository();
            final customersRepository = MockCustomersRepository();
            final customerBroadcastStream =
                customerStream.stream.asBroadcastStream();
            final siteBroadcastStream = siteStream.stream.asBroadcastStream();
            final resetBroadcastStream = resetStream.stream.asBroadcastStream();
            when(globalOptionsRepository.getMaxZoom())
                .thenAnswer((_) => Future.value(15));
            when(sessionCubit.globalOptionsRepository)
                .thenAnswer((_) => globalOptionsRepository);
            when(sessionCubit.customersRepository)
                .thenAnswer((_) => customersRepository);

            dashboardCubit = DashboardCubit(
                customerStream: customerBroadcastStream,
                siteStream: siteBroadcastStream,
                resetStream: resetBroadcastStream);
            mapboxMapCubit = MapboxMapCubit(
              customerStream: customerBroadcastStream,
              siteStream: siteBroadcastStream,
              liveMapStream: liveMapStream.stream,
              globalOptionsRepository: globalOptionsRepository,
              resetStream: resetBroadcastStream,
            );
            //mapboxMapCubit.mapboxController
            siteStream.add(site1());
            customerStream.add(customer1());
            await pumpWithSettle(
              tester,
              GoldenApp(
                theme: theme,
                scale: scale,
                child: BlocProvider<SessionCubit>(
                    create: (context) => sessionCubit,
                    child: MultiBlocProvider(
                      providers: [
                        BlocProvider(create: (context) => mapboxMapCubit),
                        BlocProvider(create: (context) => dashboardCubit)
                      ],
                      child: MyMapboxMap(isFullscreen: true,)
                    )),
              ),
            );
            await expectLater(
              find.byType(MyMapboxMap),
              matchesGoldenFile(
                'goldens/dashboard_${scale.name}_${theme.name}_${physicalSizeDevices.name}.png',
              ),
            );
          });
        }
      }
    }
  });
}
class CrowdKeepMapboxMap extends StatefulWidget {
  const CrowdKeepMapboxMap({
    Key? key,
    this.height,
    required this.isFullscreen,
  }) : super(key: key);

  final bool isFullscreen;
  final double? height;

  @override
  State<CrowdKeepMapboxMap> createState() => _CrowdKeepMapboxMapState();
}

class _CrowdKeepMapboxMapState extends State<CrowdKeepMapboxMap> {
  MapboxMapController? _controller;
  MapManager? _mapManager;
  @override
  Widget build(BuildContext context) {
    return Container(
      height: widget.height,
      child: BlocConsumer<MapboxMapCubit, MapboxMapState>(
        listener: (context, state) async {
          if (state is Completed) {
            if (state.forceUpdate) {
              print("did run by the listener");
              if (_controller != null)
                await MapUtils.fitBound(_controller!, state.floorPlan);
              await addBackgroundFloorToMap(context);
              await addNewAreasToMap(state.site, context);
            }
            await addNewNodesToMap(state.site, state.customer, context);
          }
          print("state is $state");
        },
        builder: (context, state) => state.maybeWhen(
          completed: (
            site,
            customer,
            forceUpdate,
            _,
            __,
            floorPlan,
            maxZoom,
            liveMapActive,
            ____,
          ) =>
              Stack(
            children: [
              MapboxMap(

                trackCameraPosition: true,
                compassEnabled: false,
                annotationOrder: MapUtils.annotationOrder,
                minMaxZoomPreference:
                    MinMaxZoomPreference(5, maxZoom.toDouble()),
                gestureRecognizers: MapUtils.gestureRecognizers,
                onStyleLoadedCallback: () async {
                  if (state is Completed) {
                    print("state is completed");
                    if (_controller != null) {
                      // if (_controller!.cameraPosition?.zoom.isNaN ?? false) {

                      // }
                      await Future.delayed(Duration(milliseconds: 80));
                      if(floorPlan.mapOrientation?.bearing!= null) await _controller!.moveCamera(CameraUpdate.bearingTo(double.parse(floorPlan.mapOrientation!.bearing!)));
                      await MapUtils.fitBound(_controller!, floorPlan);

                    }
                    await addBackgroundFloorToMap(context);
                    await addNewAreasToMap(site, context);
                    await addNewNodesToMap(site, customer, context);
                  }
                },
                logoViewMargins: Point(-100, -100),
                attributionButtonMargins: Point(-100, -100),
                onMapClick: (point, coordinates) {
                  _mapManager?.cleanPin();
                  context.read<DashboardCubit>().closePersonCard();
                },
                onCameraIdle: () {
                  final camera = _controller?.cameraPosition;
                  if (camera != null && !camera.zoom.isNaN) {
                    final mapManager =
                        context.read<MapboxMapCubit>().mapManager;
                    if (camera.zoom > 20 && mapManager?.size != 30) {
                      mapManager?.size = 30;
                      addNewNodesToMap(site, customer, context);
                      mapManager?.recoverPin();
                    } else if (camera.zoom <= 20 && mapManager?.size != 20) {
                      mapManager?.size = 20;
                      addNewNodesToMap(site, customer, context);
                      mapManager?.recoverPin();
                    }
                  }
                },
                onMapCreated: (MapboxMapController controller) async {
                  this._controller = controller;
                  context.read<MapboxMapCubit>().mapboxController = controller;

                  _mapManager = MapManager(controller);
                  context.read<MapboxMapCubit>().mapManager = _mapManager;

                  controller.onSymbolTapped.add(_onSymbolTapped);
                },
                accessToken:
                    "pk.eyJ1IjoicnVpYnJhcy1jayIsImEiOiJjbGZ2YXpkYzMwMm43M3RsaWxicmNhdTRlIn0.ft9tbUAjc5IGRPrAQrFDog",
                initialCameraPosition: MapUtils.getInitialCurrent(site),
              ),
              MyLive(liveMapActive: liveMapActive),
              Positioned(
                bottom: mapPadding,
                right: mapPadding,
                child: PopupMenuButton<int>(
                  child: MyContainer(
                    color: inputFocusedBorderColor,
                    child: Center(
                      child: Text(
                        context.read<MapboxMapCubit>().getLevel().toString(),
                        style: TextStyle(
                          color: secondaryBackgroundColor,
                          fontWeight: FontWeight.w700,
                          fontFamily: "Poppins",
                          fontSize: 20,
                        ),
                      ),
                    ),
                  ),
                  onSelected: (selectedFloorLevel) {
                    context
                        .read<MapboxMapCubit>()
                        .setFloorByIndex(site, customer, selectedFloorLevel);
                    context.read<DashboardCubit>().changeFloor(
                          site: site,
                          selectedFloorLevel: selectedFloorLevel,
                        );
                  },
                  itemBuilder: (BuildContext bc) {
                    int index = 0;
                    return FireStoreUtils.getFloors(site)!
                        .map(
                          (floor) => PopupMenuItem(
                            enabled: floor.key !=
                                (context
                                        .read<MapboxMapCubit>()
                                        .floorPlanSelected
                                        ?.key ??
                                    -1),
                            child: Text(floor.value.name ?? ""),
                            value: index++,
                          ),
                        )
                        .toList();
                  },
                ),
              ),
              Positioned(
                top: mapPadding,
                right: mapPadding * 2 + mapButtonSize,
                child: SafeArea(
                  child: Center(
                    child: Visibility(
                      child: MyContainer(
                        staticWidth: null,
                        color: inputBackgroundColor,
                        child: FilterButton(),
                      ),
                      visible: widget.isFullscreen,
                    ),
                  ),
                ),
              ),
              Positioned(
                top: mapPadding,
                right: mapPadding,
                child: SafeArea(
                  child: InkWell(
                    onTap: () =>
                        context.read<DashboardCubit>().changeFullscreen(),
                    child: MyContainer(
                      color: inputBackgroundColor,
                      child: Center(
                        child: Icon(
                          context.read<DashboardCubit>().state.maybeMap(
                                ready: (ready) => ready.isFullscreen
                                    ? Icons.fullscreen_exit
                                    : Icons.fullscreen,
                                orElse: () => Icons.fullscreen,
                              ),
                        ),
                      ),
                    ),
                  ),
                ),
              ),
            ],
          ),
          orElse: () => Center(child: CircularProgressIndicator()),
        ),
      ),
    );
  }

above is the widget test file and my widget.

here goes my fvm flutter doctor

Doctor summary (to see all details, run flutter doctor -v): [!] Flutter (Channel stable, 3.7.11, on macOS 13.3.1 22E772610a darwin-arm64, locale en-US) ! Warning: dart on your path resolves to /opt/homebrew/Cellar/dart/3.1.3/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/andrecoelho/fvm/versions/3.7.11. Consider adding /Users/andrecoelho/fvm/versions/3.7.11/bin to the front of your path. [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2) [✓] Xcode - develop for iOS and macOS (Xcode 14.3) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.1) [✓] VS Code (version 1.77.1) [✓] Connected device (3 available) [✓] HTTP Host Availability

the map is all fine when running i just would like to do some widget tests.

even when doing a simple test i get that exception, example of the simple test

await pumpWithSettle(
              tester,
              GoldenApp(
                theme: theme,
                scale: scale,
                child: MapboxMap(initialCameraPosition: CameraPosition(target: LatLng(0, 0)),)

              ),
            );

i'm using the latest version of mapbox: mapbox_gl: ^0.16.0

stale[bot] commented 7 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.