So I may have a slightly unique situation here, but I have a function that runs in my main.dart file that listens for a firebase dynamic link to log my user in (magic link). What I would like is for my welcome page to show a message that lets the user know there was some problem with the magic link they clicked on.
Listening to States that are updated elsewhere
Custom Code
I first just created an app state called magicLinkError boolean, then added a text widget with conditional visibility looking at this app state. However, when the state is updated, the page does rebuild, meaning the message will not appear.
Next, I created a custom widget that uses the consumer method (help from chatGPT) and is supposedly meant to rebuild if the listened to item changes. According to chatGPT, I also needed to add a notifyListeners() method to the setter function.
Widget:
import 'package:provider/provider.dart';
class MagicLinkErrorWidget extends StatefulWidget {
const MagicLinkErrorWidget({
super.key,
this.width,
this.height,
required this.errorText,
});
final double? width;
final double? height;
final String errorText;
@override
State<MagicLinkErrorWidget> createState() => _MagicLinkErrorWidgetState();
}
class _MagicLinkErrorWidgetState extends State<MagicLinkErrorWidget> {
@override
Widget build(BuildContext context) {
return Consumer<FFAppState>(
builder: (context, appState, child) {
return appState.magicLinkErrored
? Container(
width: widget.width,
height: widget.height,
padding: EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.1),
borderRadius: BorderRadius.circular(8.0),
),
child: Text(
widget.errorText,
style: FlutterFlowTheme.of(context).bodyMedium.override(
fontFamily: 'Lato',
color: FlutterFlowTheme.of(context).error,
fontSize: valueOrDefault<double>(
fontSizeWithScaleFactorMinMax(
25.0, 14.0, 16.0, appState.scaleFactor),
16.0,
),
letterSpacing: 0.0,
),
),
)
: SizedBox.shrink(); // Display nothing if no error
},
);
}
}
State:
bool _magicLinkErrored = false;
bool get magicLinkErrored => _magicLinkErrored;
set magicLinkErrored(bool value) {
_magicLinkErrored = value;
notifyListeners();
}
Doing this still results in the exact same behavior.
No
1