rrousselGit / functional_widget

A code generator to write widgets as function without loosing the benefits of classes.
596 stars 46 forks source link

How to declare static properties #101

Closed coyksdev closed 2 years ago

coyksdev commented 2 years ago

Is there a way to achieve this using functional widget?

class MyPage extends StatelessWidget {
  static const routeName = "/my-page";

  const MyPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}
chientrm commented 2 years ago
@hcwidget
Widget app(WidgetRef ref) => MaterialApp(
...
      routes: {
        Routes.auth: (_) => const SignInScreen(),
        Routes.home: (_) => const HomePage(),
        Routes.store: (_) => const StorePage(),
        Routes.profile: (_) => const ProfilePage(),
        Routes.loading: (_) => const Scaffold(
            body: SafeArea(child: Center(child: CircularProgressIndicator()))),
      },
    );
class Routes {
  static const auth = '/auth';
  static const home = '/home';
  static const store = '/store';
  static const profile = '/profile';
  static const loading = '/loading';
}
rrousselGit commented 2 years ago

Defining static properties is not supported and likely isn't something that can be supported.

I'd suggest waiting until Dart implements static extensions, at which point you should be able to define them on your own. In the meantime, you likely can implement your code without relying on a static function