Home > OS >  What is the best way to do nothing here, where I am using a consumer widget?
What is the best way to do nothing here, where I am using a consumer widget?

Time:11-28

I am trying to write keep the override part to do nothing since I don't want to implement anything. How would I do it with a consumer widget.

I know in stateful widget it is something like this:

_MyAppState createState() => _MyAppState();

How can I do same for consumer widget below:

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

  void signInWithGoogle(BuildContext context, WidgetRef ref) {
    ref.read(authControllerProvider).signInWithGoogle();
  }

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    // TODO: implement build
    throw UnimplementedError();
  }
} 

CodePudding user response:

If you don't want to do anything within your build method, you can just return a SizedBox.shrink() widget:

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SizedBox.shrink();
  }
}

  • Related