1

I have tried to make it in the row, but then I don't have anything in the screen. How do you solve it in Flutter?

appbar

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 10.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          const Text(
            "Goals",
            style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),

search

@override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 10),
      child: Container(
        height: 55,
        decoration: BoxDecoration(
          color: Colors.grey[200],
        ),
        child: TextFormField(
          decoration: const InputDecoration(
            prefixIcon: Icon(Icons.search),
            hintText: "Search",
            hintStyle: TextStyle(
              color: Colors.black,
            ),
            enabledBorder: OutlineInputBorder(
              borderSide: BorderSide.none,
            ),
            focusedBorder: OutlineInputBorder(
              borderSide: BorderSide.none,
            ),
          ),
        ),
      ),
    );

in Screen I have tried make these two widgets it in Row, but doesn't work

return Scaffold(
      body: SafeArea(
        child: ListView(
          children: <Widget>[
            const CustomAppBar(),
            const SearchBar(),

This is my result:

Example

EDIT:

            Row(
              children: [
                Padding(
                  padding: const EdgeInsets.all(24.0),
                  child: Text("Goals"),
                ),
                Expanded(child: MyPrefilledSearch()),
              ],
            ),
class MyPrefilledSearch extends StatefulWidget {
  const MyPrefilledSearch({Key? key}) : super(key: key);

  @override
  State<MyPrefilledSearch> createState() => _MyPrefilledSearchState();
}

class _MyPrefilledSearchState extends State<MyPrefilledSearch> {
  @override
  Widget build(BuildContext context) {
    return CupertinoSearchTextField(
      onChanged: (String value) {
        print('The text has changed to: $value');
      },
      onSubmitted: (String value) {
        print('Submitted text: $value');
      },
    );
  }
}

Looks fine :) enter image description here

My post is code because it is I do not need add more text because it is not necessary.

Chris
  • 63
  • 6

1 Answers1

1

You can use CupertinoSearchTextField()

Example from doc

Padding(
  padding: const EdgeInsets.all(8.0),
  child: Center(
    child: CupertinoSearchTextField(),
  ),
),

enter image description here

 Row(
  children: [
    Padding(
      padding: const EdgeInsets.all(8.0),
      child: Text("Goals"),
    ),
    Expanded(child: CupertinoSearchTextField()),
  ],
),

enter image description here

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56