I was trying to follow solution 1 in @rmtmckenzie's answer to a similar question (Persisting AppBar Drawer across all Pages Flutter but when I try the following code, I get the error The argument type 'SaneAppBar' can't be assigned to the parameter type 'PreferredSizeWidget?'. Since I can assign a non-nullable member to a nullable member (e.g. String? = String), I don't get what I'm doing wrong. Perhaps this is something you can do with a drawer parameter but not with an appBar parameter? If so, I'd appreciate any pointers to how I should have been able to determine this up front. I'm also wondering if the sample code needs to be modified to work in a null-safety environment?
sane_app_bar.dart:
import 'package:flutter/material.dart'; class SaneAppBar extends StatelessWidget { @override Widget build(BuildContext context) { return AppBar( title: const Text('SANE Finder'), centerTitle: true, ); } }
Used this way by my screen widget:
class _WelcomeScreenState extends State<WelcomeScreen> { @override Widget build(BuildContext context) { return Scaffold( appBar: SaneAppBar(), body: Padding(...
https://stackoverflow.com/questions/67342265/how-to-share-an-appbar-between-multiple-screens May 01, 2021 at 09:56AM
没有评论:
发表评论