DEV Community

Cover image for Show me your main.dart - Flutter research

Show me your main.dart - Flutter research

Keff on August 31, 2021

Do you work on a Flutter project? If so, please share your main.dart file with me (if you want and can). I'm researching how people organize their...
Collapse
 
iizmotabar profile image
Motabar Javaid • Edited

Here's mine: main.dart screenshot

Collapse
 
manumrigank profile image
MANUMRIGANK

Which editor is this?
*note newbie here

Collapse
 
nombrekeff profile image
Keff

I think it's not an editor, most likely something like carbon, it converts code into imagesx like the one shown above! A rather neat site

Thread Thread
 
manumrigank profile image
MANUMRIGANK

Oh!
Thanks

Collapse
 
iizmotabar profile image
Motabar Javaid

Hey, Sorry for the late reply. @nombrekeff is right. Its a code beautifier ray.so . But the one Keff mentioned also does the same job :)

Thread Thread
 
manumrigank profile image
MANUMRIGANK • Edited

Thanks
Can I somehow get this color and/or Background in VS Code?

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.

Collapse
 
aviadkatani_68 profile image
Aviad • Edited

Hi, this is mine:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await GetStorage.init('MainStorage');
  await PushNotificationService.initializeApp();
  initializeDateFormatting().then(
    (_) => runApp(
      MyApp(),
    ),
  );
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
nombrekeff profile image
Keff

I'll start, this is one of mine:

import 'package:flutter/material.dart';
import 'package:pegues/api/local/loading.dart';
import 'package:pegues/app.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  Loading.setup();

  runApp(const PeguesApp());
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
spiderbezno profile image
Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
nombrekeff profile image
Keff

Would you mind sharing it? no problem if you dont't, but I'd love to see it. Also, have you always done your main.dart file like that, or have experimented and landed on that specific way?

Collapse
 
grahamthedev profile image
GrahamTheDev • Edited

Comment for the algo -4C

Collapse
 
cahyowhy profile image
cahyo wibowo • Edited

Here's mine:
using catcher plugins

Alt text of image

Collapse
 
nombrekeff profile image
Keff

Thanks for the addition @cahyowhy . I like that you're handling errors, great stuff! did not know about catcher either (I'm discovering a load of cool packages from this post), we use Sentry at our company for this.