2

I am new with flutter. I would like to custom a search widget on SliverAppBar.

On scroll up, I would like it show this search widget with a flexible to nearly cart button as show in pictures.

Code

  final expandedHeight = 150.0;

  @override
  Widget build(BuildContext context) {
    final products = Provider.of<ProductProvider>(context).products;
    return Scaffold(
      key: _scaffoldKey,
      drawer: CuzAppDrawer(),
      body: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            SliverAppBar(
              expandedHeight: expandedHeight,
              floating: false,
              pinned: true,
              flexibleSpace: FlexibleSpaceBar(
                centerTitle: true,
                title: GestureDetector(
                  onTap: () => null,
                  child: Padding(
                    padding:
                        EdgeInsets.symmetric(horizontal: paddingThemeScreen()),
                    child: Container(
                        height: 30,
                        decoration: BoxDecoration(
                          color: nearlyWhite,
                          borderRadius: BorderRadius.circular(24),
                        ),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            const SizedBox(width: 10),
                            const Icon(Feather.search,
                                color: Colors.grey, size: 15),
                            const SizedBox(width: 5),
                            Text("Search product",
                                style: TextStyle(
                                    color: Colors.grey,
                                    fontSize: 12,
                                    fontWeight: FontWeight.w200))
                          ],
                        )),
                  ),
                ),
                background: Image.network(
                  "image-url",
                  fit: BoxFit.cover,
                ),
              ),
            ),
          ];
        },

Result

enter image description here

Expected result

enter image description here

James Z
  • 12,209
  • 10
  • 24
  • 44
Wzo
  • 111
  • 7

0 Answers0