当我尝试在同一小部件中创建银条应用程序栏和页面浏览量时出现问题



我在使用我的应用程序时遇到了逻辑问题我想要一个银色的appBar与页面视图在同一小部件,当我这样做,并为我的页面浏览量的每个页面分配一个自定义滚动视图,我得到的问题,但如果我在页面的每个页面上声明一个条子应用程序条,它工作得很好,同时我不应该有嵌套的滚动视图在我的页面浏览量小部件现在我不认为我应该写一个应用程序条为每一个当我可以写它我的页面浏览量小部件任何的想法这是我的代码

Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        top: true,
        bottom: false,
        child:
         NestedScrollView(
          floatHeaderSlivers: true,
            headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
              return <Widget>[
                  SliverOverlapAbsorber(
                    handle: NestedScrollView.sliverOverlapAbsorberHandleFor(
                        context),         
        sliver:
               SliverAppBar(
        // toolbarHeight: 50,
        backgroundColor: Color.fromRGBO(255, 255, 255, 1),
        title: const Text(
          'Partnerna',
          style: TextStyle(
              fontSize: 21,
              fontWeight: FontWeight.bold,
              fontStyle: FontStyle.normal,
              color: linerColorUp),
        ),
        actions: [
          Padding(
            padding: const EdgeInsets.symmetric(
                vertical: 0, horizontal: 10),
            child: Container(
              alignment: Alignment.centerRight,
              // color: Colors.amber,
              // width: double.infinity,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: const [
                  CircelCntainerBackgroundWidget(
                      backGroundColor: buttonbackgroundcolor,
                      child: Padding(
                        padding: EdgeInsets.all(3),
                        child: FaIcon(
                          FontAwesomeIcons.squarePlus,
                          size: 18,
                        ),
                      )),
                  SizedBox(
                    width: 20,
                  ),
  
              CircelCntainerBackgroundWidget(
                  backGroundColor: buttonbackgroundcolor,
                  child: Icon(
                    Icons.notification_add_rounded,
                    size: 21,
                  )),
              SizedBox(
                width: 20,
              ),
  
              // SizedBox(width: 10,),
              CircleAvatar(
                radius: 14,
                backgroundImage: NetworkImage(
                    "https://th.bing.com/th/id/OIP.2tWiaVWFJjvC1HhJQuTtCwHaHt?w=173&h=181&c=7&r=0&o=5&pid=1.7"),
              ),
            ],
          ),
        ),
      )
    ],
    // expandedHeight: 200,
    floating: true,
    pinned: false,
    snap: true,
    forceElevated: innerBoxIsScrolled,
    elevation: 0,
      ),
              )];
        },
        body:
           PageView(
            children: [
              HomeScreen(),
              ConnectScreen(),
              ConnectRequestScreen(),
              MessagScrenn(),
              SettingScreen(),
            ],
            physics: const NeverScrollableScrollPhysics(),
            controller: pageController,
            onPageChanged: onPageChange,
          ),
  ),),

尝试制作一个与代码相同的自定义Scaffold,以包装每个PageView子元素。

class MyHomePage extends StatefulWidget {
  const MyHomePage({
    Key? key,
  }) : super(key: key);
  @override
  _MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: PageView(
        children: [
          Page1(),
          Page2(),
          Page3(),
        ]
      ),
    );
  }
}
class Page1 extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return CustomScaffold(
      body: (...)
    );
  }
}
class Page2 extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return CustomScaffold(
      body: (...)
    );
  }
}
class Page3 extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return CustomScaffold(
      body: (...)
    );
  }
}
class CustomScaffold extends StatefulWidget {
  final Widget body;
  const CustomScaffold({ Key? key, required this.body}) : super(key: key);
  @override
  _CustomScaffoldState createState() => _CustomScaffoldState();
}
class _CustomScaffoldState extends State<CustomScaffold> {
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: NestedScrollView(
        headerSliverBuilder: (context, innerBoxIsScrolled){
          (...)
        },
        body: widget.body,
      ),
    );
  }
}

相关内容

  • 没有找到相关文章

最新更新