Julia Pak
Julia Pak

Reputation: 743

Flutter riverpod generator: The argument type 'Object?' can't be assigned to the parameter type 'RouterDelegate<Object>?'

I am trying to follow along with this tutorial/project here supabase_riverpod_minicourse.

It involves making some auto generated providers. dart run build_runner watch -d and it seems to work ok.

However I've come into an issue with my routes, I keep getting this error:

The argument type 'Object?' can't be assigned to the parameter type 'RouterDelegate<Object>?'

underlining routerDelegate: routes in this file here:

import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:nubztrade/providers/core.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Supabase.initialize(
    url: supabaseUrl,
    anonKey: supabaseAnonPublicKey,
  );
  //run the app
  runApp(const ProviderScope(
    child: EnterApp(),
  ));
}

class EnterApp extends ConsumerWidget {
  const EnterApp({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final routes = ref.read(routeProvider);
    

    return MaterialApp.router(
      debugShowCheckedModeBanner: false,
      routerDelegate: routes,
    );
  }
}

I have tried type casting like this, but I don't think its correct.

...
    final routes = ref.read(routeProvider) as RouterDelegate<Object>?;

    return MaterialApp.router(
      debugShowCheckedModeBanner: false,
      routerDelegate: routes,
    );
 

Here is my routes file:

part 'routes.g.dart';

@riverpod
route(RouteRef _) => _routes;

final _routes = GoRouter(
  initialLocation: '/',
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) => const MainView(),
    ),
    GoRoute(
      path: '/login',
      builder: (context, state) => const LoginPage(),
    ),
  ],
);

And this is what my generated routes.g.dart file looks like:

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'routes.dart';

// **************************************************************************
// RiverpodGenerator
// **************************************************************************

String _$routeHash() => r'6d3d0aea1ed0cc6ebe5d911cdda7e90bfaedfbec';

/// See also [route].
@ProviderFor(route)
final routeProvider = AutoDisposeProvider<Object?>.internal(
  route,
  name: r'routeProvider',
  debugGetCreateSourceHash:
      const bool.fromEnvironment('dart.vm.product') ? null : _$routeHash,
  dependencies: null,
  allTransitiveDependencies: null,
);

typedef RouteRef = AutoDisposeProviderRef<Object?>;
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member

It looks like RouteRef = AutoDisposeProviderRef<Object?>; used to be RouteRef = AutoDisposeProviderRef<dynamic>; and I am not sure what to do about this!

If you can help me I would be grateful!

edit: I just changed this and I think it works?!

dynamic route(RouteRef _) => _routes;

Upvotes: 1

Views: 66

Answers (0)

Related Questions