I get the following error message:
The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type.
Try adding either a return or a throw statement at the end.
While trying to use an observable variable using the following code:
Obx((){ElevatedButton(
child: Text(_authMode.value == AuthMode.Login ? 'LOGIN' : 'SIGN UP'),
onPressed: _submit,
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
primary: Theme.of(context).primaryColor,
padding: const EdgeInsets.symmetric(
horizontal: 30.0, vertical: 8.0),
onPrimary: Theme.of(context).primaryTextTheme.button!.color,
))},
),
Obx((){ TextButton(
child: Text(
'${_authMode.value == AuthMode.Login ? 'SIGN UP' : 'LOGIN'} '),
onPressed: _switchAuthMode,
style: TextButton.styleFrom(
padding:
const EdgeInsets.symmetric(horizontal: 30.0, vertical: 4),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
textStyle: TextStyle(color: Theme.of(context).primaryColor),
))
}),
I don't know how to fix it?
CodePudding user response:
You are not returning anything from the Obx
lambda. But it requires a Widget
to be returned. Try changing like this:
Obx((){
return ElevatedButton(....);});
And:
Obx((){
return TextButton(...);});
You are just missing the return
keyword.
Or you may like to use the fat arrow syntax without the return
keyword like:
Obx(()=> ElevatedButton(...));