skip to Main Content

I want to add textfield in bottom appbar. I used bottom and PreferredSize in my appbar, but the textfield still not showing

this is the image
enter image description here

and this is all code

import 'package:flutter/material.dart';

import '../../utils/utils.dart';

class MaterialRequestScreen extends StatefulWidget {
  const MaterialRequestScreen({super.key});

  @override
  State<MaterialRequestScreen> createState() => _MaterialRequestScreenState();
}

class _MaterialRequestScreenState extends State<MaterialRequestScreen> {
  TextEditingController searchC = TextEditingController();

  @override
  void initState() {
    searchC.text = 'hallo';
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(AppStrings.materialRequest),
        centerTitle: true,
        backgroundColor: AppColor.neutral50,
        bottomOpacity: 0.0,
        bottom: PreferredSize(
            preferredSize: Size.fromHeight(kToolbarHeight),
            child: Container(
              color: Colors.red,
              child: TextField(
                controller: searchC,
                decoration: InputDecoration(
                  filled: true,
                  fillColor: AppColor.neutral500,
                  prefixIcon: Icon(Icons.search),
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(8.0),
                    borderSide: BorderSide.none,
                  ),
                  hintText: 'Search...',
                ),
              ),
            )),
      ),
    );
  }
}

I want to like this
enter image description here

2

Answers


  1. AppBar(
          toolbarHeight: 80,
          title: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text("Title"),
              TextField(
                decoration: InputDecoration(hintText: "Your text"),
              )
            ],
          ),
        ),
    
    Login or Signup to reply.
  2. try this code

    Scaffold(
          appBar: PreferredSize(
            preferredSize: Size.fromHeight(120.0), // Set the height of the AppBar
            child: AppBar(
              automaticallyImplyLeading: false, // Removes default back button
              flexibleSpace: Column(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  AppBar(
                    automaticallyImplyLeading: true, // Adds back button
                    title: Text('Material Request'),
                    elevation: 0,
                  ),
                  Padding(
                    padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
                    child: Container(
                      height: 40,
                      decoration: BoxDecoration(
                        color: Colors.grey[200],
                        borderRadius: BorderRadius.circular(8.0),
                      ),
                      child: TextField(
                        decoration: InputDecoration(
                          hintText: 'Search for an item',
                          border: InputBorder.none,
                          prefixIcon: Icon(Icons.search),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
              elevation: 0,
            ),
          ),
          body: Center(
            child: Text('Body Content'),
          ),
    

    you will get results something like this:
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search