Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big white space between search bar and list of words #4

Closed
TokisakiKurumi2001 opened this issue Sep 13, 2020 · 7 comments
Closed

Big white space between search bar and list of words #4

TokisakiKurumi2001 opened this issue Sep 13, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@TokisakiKurumi2001
Copy link
Owner

Simulator Screen Shot - iPhone 11 Pro Max - 2020-09-13 at 21 11 15

@TokisakiKurumi2001 TokisakiKurumi2001 added the bug Something isn't working label Sep 13, 2020
@TokisakiKurumi2001
Copy link
Owner Author

TokisakiKurumi2001 commented Sep 14, 2020

This is one of the approach to reduce the space.

Firstly, the space is created due to the height of Container inside lib/home/components/header_with_searchbox.dart:

Before:

class HeaderWithSearchBox extends StatelessWidget {
  const HeaderWithSearchBox({
    Key key,
    @required this.size,
  }) : super(key: key);
  final Size size;
  @override
  Widget build(BuildContext context) {
    return Container(
     margin: EdgeInsets.only(bottom: 20.0 * 2.5),
      height: size.height * 0.2,

Therefore, we reduce the height to 0.12 * size.height. At the same time, remove the margin bottom.
After:

class HeaderWithSearchBox extends StatelessWidget {
  const HeaderWithSearchBox({
    Key key,
    @required this.size,
  }) : super(key: key);
  final Size size;
  @override
  Widget build(BuildContext context) {
    return Container(
      height: size.height * 0.12,

However, this fix will lead to big corruption in search bar(search bar moving upward near appbar). In order to fix this, we replace bottom: 70 in Positioned with top: 45.

Before,

Widget build(BuildContext context) {
    return Container(
      height: size.height * 0.12,
      child: Stack(
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(
              left: 20.0,
              right: 20.0,
              bottom: 56,
            ),
            height: size.height * 0.2 - 100,
            decoration: BoxDecoration(
              color: Colors.blue,
              borderRadius: BorderRadius.only(
                bottomLeft: Radius.circular(36),
                bottomRight: Radius.circular(36),
              ),
            ),
          ),
          Positioned(
            bottom: 70,
            left: 0,
            right: 0,

After,

Widget build(BuildContext context) {
    return Container(
      height: size.height * 0.12,
      child: Stack(
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(
              left: 20.0,
              right: 20.0,
              bottom: 56,
            ),
            height: size.height * 0.2 - 100,
            decoration: BoxDecoration(
              color: Colors.blue,
              borderRadius: BorderRadius.only(
                bottomLeft: Radius.circular(36),
                bottomRight: Radius.circular(36),
              ),
            ),
          ),
          Positioned(
            top: 45,
            left: 0,
            right: 0,

@TokisakiKurumi2001
Copy link
Owner Author

Simulator Screen Shot - iPhone 11 Pro Max - 2020-09-14 at 10 23 15

@TokisakiKurumi2001
Copy link
Owner Author

Screenshot 2020-09-14 at 17 03 55

@TokisakiKurumi2001
Copy link
Owner Author

iPhone 6s Plus seems not to work very well with this approach

@TokisakiKurumi2001
Copy link
Owner Author

2020_09_14_04_57_42

@TokisakiKurumi2001
Copy link
Owner Author

Neither does this Samsung phone.

@TokisakiKurumi2001
Copy link
Owner Author

Here is the suggestion for making pinned search bar when scrolling and also fixing the blank space:

lib/home/home_page.dart>HomeScreen>Scaffold>CustomScrollView

SliverPersistentHeader(
            pinned: true,
            delegate: PersistentHeader(
              widget: HeaderWithSearchBox(size: size),
            ),
          ),
          SliverList(
            delegate: SliverChildListDelegate(
              [
                Column(
                  children: <Widget>[
                    Word(),
                  ],
                ),
              ],
            ),
          ),

lib/home/�components/header_with_searchbox.dart

class HeaderWithSearchBox extends StatelessWidget {
  const HeaderWithSearchBox({
    Key key,
    @required this.size,
  }) : super(key: key);
  final Size size;
  @override
  Widget build(BuildContext context) {
    return Container(
      height: size.height * 0.12,
      child: Stack(
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(
              left: 20.0,
              right: 20.0,
              bottom: 56,
            ),
            /*
            height: size.height * 0.2 - 100,
            decoration: BoxDecoration(
              color: Colors.blue,
              borderRadius: BorderRadius.only(
                bottomLeft: Radius.circular(36),
                bottomRight: Radius.circular(36),
              ),
            ),
             */
          ),

/* ........................... */

class PersistentHeader extends SliverPersistentHeaderDelegate {
  final Widget widget;

  PersistentHeader({this.widget});

  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    return Container(
      width: double.infinity,
      height: 105.0,
      child: Card(
        margin: EdgeInsets.all(0),
        color: Colors.white,
        elevation: 0,
        child: Center(child: widget),
      ),
    );
  }

  @override
  double get maxExtent => 105.0;

  @override
  double get minExtent => 105.0;

  @override
  bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
    return true;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant