I can't solve this null safety issue. I've tried a million options, and I'm still getting an error. Any help would be appreciated.
Here's the error. It keeps saying I'm I'm passing a String? to a String, but I don't see how?
Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't.
data: _pageManager.returnMarkdown(widget.documentName!)),
Here's the code that produces the error:
class MarkdownWidget extends StatefulWidget {
const MarkdownWidget({
Key? key,
this.width,
this.height,
this.documentName,
}) : super(key: key);
final double? width;
final double? height;
final String? documentName;
@override
_MarkdownWidgetState createState() => _MarkdownWidgetState();
}
class _MarkdownWidgetState extends State<MarkdownWidget> {
final PageManager _pageManager = PageManager();
final scaffoldKey = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return Scaffold(
key: scaffoldKey,
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
body: SafeArea(
child: GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 1,
decoration: BoxDecoration(),
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(5, 80, 5, 0),
child: Markdown(
data: _pageManager.returnMarkdown(widget.documentName!)),
),
)
],
),
),
),
);
}
}
class PageManager {
String? privacy = """
# Privacy Policy
""";
String? terms = """
# Agreement To Terms of Use
""";
String? returnMarkdown(String? pageName) {
if (pageName! == null) {
return 'Nothing to see here.';
}
switch (pageName) {
case 'Privacy':
{
return privacy;
}
case 'Terms':
{
return terms;
}
}
}
}
Thank you for any help on this issue.