Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
993 views
in Technique[技术] by (71.8m points)

flutter - Positioned Widget overlapping my CustomScrollView

I have a CustomScrollView that I need a fixed text entry field at the bottom. A post here suggestion a Stack with a Positioned Widget which worked great:

Scaffold(
  appBar: appBarBuilder == null ? null : appBarBuilder(context),
  body: RefreshIndicator(
    onRefresh: onRefresh,
    child: Stack(
      children: <Widget>[
        CustomScrollView(
          controller: controller,
          slivers: <Widget>[
            if (showImage)
              SliverAppBar(
                expandedHeight: showImage ? 100 : 50,
                title: showImage ? image : null,
                centerTitle: true,
                floating: true,
                pinned: false,
              ),
            sliverList,
          ],
        ),
        Positioned(
          bottom: 0,
          left: 0,
          right: 0,
          child: TextFormField(),
        ),
      ],
    ),
  ),
);

Except that the positioned widget overlaps my CustomScrollView. I could add a white background, but I'd rather the CustomScrollView stop short of my TextFormField. How do I do that? Below is the current rendering:

enter image description here

question from:https://stackoverflow.com/questions/65832903/positioned-widget-overlapping-my-customscrollview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Screenshot:

enter image description here


I'm sharing with you a simple implementation of a Column with ListView (replace it with your CustomScrollView) and a TextField at the bottom. When you click on the TextField, the keyboard automatically slides up the ListView and all your contents remain visible.

Code:

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Column(
      children: [
        Expanded(
          child: ListView.builder( // <-- Replace it with your CustomScrollView
            itemCount: 20,
            itemBuilder: (_, i) => ListTile(title: Text('Item $i')),
          ),
        ),
        Padding(
          padding: const EdgeInsets.all(20),
          child: TextField(decoration: InputDecoration(hintText: 'Enter a message')),
        )
      ],
    ),
  );
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...