DEV Community

Discussion on: Show me your main.dart - Flutter research

Collapse
 
johnny5development profile image
johnny5development • Edited

Here's mine and I have to admit, i'm excited about Riverpod. In my "InitAppCore"-Widget i'm registering all the Providers I globally need. This is bloating my widgettree. I heavily depend on the concept of ProxyProviders do you know if thats possible with RiverPod?:

import 'package:flutter/material.dart';
import 'package:AppName/src/presentation/widgets/widgets.dart';
import 'main.reflectable.dart';
import 'src/app.dart';

void main() {
  initializeReflectable();
  WidgetsFlutterBinding.ensureInitialized();
  runApp(SystemConfig(child: InitAppCore(child: AppName())));
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
nombrekeff profile image
Keff

Thanks for the addition, I have not used proxy providers not riverpod, but I found this issue where they talk about it: github.com/rrousselGit/river_pod/i...

Just as a little tip, you can add codeblocks to highlight your code. Like this:

Collapse
 
johnny5development profile image
johnny5development

Hi Keff, thank you for finding this discussion. I think this is holding me back then from using Riverpod then. I use the proxyprovider for providing a callbackfunction from the authenticator to my grpc client, so the grpcclient knows nothing about the authenticator but can always ask for an id token.
I can think of a simple solution for my bloated widgettree, if i build one inherited widget that registers all the objects in a map[class]object and just provides a getter function.

GrpcClient _initGrpcClient(
    BuildContext ctx, Future<String> Function([bool]) idToken) {
  return GrpcClient(
      GrpcSetupParameter(
          remoteHost: SystemConfig.of(ctx).getValue<String>('backendUrl'),
          remotePort: SystemConfig.of(ctx).getValue<int>('backendPort'),
          options: ChannelOptions(
            credentials: ChannelCredentials.secure(),
            idleTimeout: Duration(minutes: 1),
          )),
      interceptorBuilder: () => [
            MyAuthInterceptor.build(metadataProvider: [
              MyAuthorizationMetadataProvider(idToken: idToken),
            ])
          ],
      serviceBuilder: (c, i) => [
            FileTransferService(c, [
              i<MyAuthInterceptor>(),
            ]),
            UserProfileService(c, [
              i<MyAuthInterceptor>(),
            ]),
            SomeServiceClass(c, [
              i<MyAuthInterceptor>(),
            ]),
            SomeServiceClass(c, [i<MyAuthInterceptor>()]),
          ]);
}

Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
nombrekeff profile image
Keff

Yeah I don't now much about Riverpod, but maybe @iizmotabar knows as he has been using it.