在哪里定义命名参数'sliver'

问题描述 投票:1回答:2

所以,我正在创建一个基于qlixswpoi的基于银条的AppBar我找到的例子,我正面临着错误this

我的代码有点像这样(我知道我可能把条子放在错误的地方,但是理解这个问题的任何帮助都表示赞赏)。

named parameter 'slivers' isn't defined
flutter flutter-layout
2个回答
3
投票

确实Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, floatingActionButton: FloatingActionButton( backgroundColor: Colors.white, onPressed: () {}, child: Icon( CommunityMaterialIcons.plus, color: Colors.black, ), ), slivers: <Widget>[ // *problematic sliver here* SliverAppBar( pinned: true, expandedHeight: 256.0, flexibleSpace: FlexibleSpaceBar( title: Text('po.'), ), ), ], body: ListView.builder( itemCount: tracks.length, itemBuilder: (BuildContext context, int index) { // the rest of the itembuilder continued here 字段没有为slivers定义。像qzxswpoi一样包装appbar和listview,如下所示:

Scaffold

以下是您提供的固定要点:

NestedScrollView

0
投票

在体内你冷设置一个SliverList并将子计数设置为0.类似于:

Widget build(BuildContext context) => Scaffold(
        backgroundColor: Colors.white,
        floatingActionButton: FloatingActionButton(
          backgroundColor: Colors.white,
          onPressed: () {},
          child: Icon(
            Icons.plus_one,
            color: Colors.black,
          ),
        ),
        body: NestedScrollView(
            headerSliverBuilder:
                (BuildContext context, bool innerBoxIsScrolled) {
              return <Widget>[
                SliverAppBar(
                  pinned: true,
                  expandedHeight: 256.0,
                  flexibleSpace: FlexibleSpaceBar(
                    title: Text('po.'),
                  ),
                ),
              ];
            },
            body: ListView.builder(
              padding: EdgeInsets.all(8.0),
              itemExtent: 20.0,
              itemBuilder: (BuildContext context, int index) {
                return Text('entry $index');
              },
            )));

通常我用import 'package:flutter/material.dart'; void main() { runApp(MaterialApp( theme: ThemeData.dark(), debugShowCheckedModeBanner: false, home: Home(), )); } class Home extends StatelessWidget { final tracks = const [ {'title': 'BCS Examination', 'subtitle': 'Something'}, {'title': 'Dhaka University Admission'}, {'title': 'Khulna University Admission'}, {'title': 'Chottogram University Admission'}, {'title': 'Bank Job Exam'}, {'title': 'Bank Job Exam'} ]; @override Widget build(BuildContext context) => Scaffold( floatingActionButton: FloatingActionButton( backgroundColor: Colors.white, onPressed: () {}, child: Icon( Icons.info, color: Colors.black, ), ), body: NestedScrollView( headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { return <Widget>[ SliverAppBar( pinned: true, expandedHeight: 256.0, flexibleSpace: FlexibleSpaceBar( title: Text('po.'), ), ), ]; }, body: ListView.builder( itemCount: tracks.length, itemBuilder: (BuildContext context, int index) { var trackTitles = tracks[index]; return Text(trackTitles['title']); }), )); } 使用它,但你可以尝试。

© www.soinside.com 2019 - 2024. All rights reserved.