-1

I need to make a search page. Made by means of TextField a field on clicking on which the page of search should open. Tell me how to implement clicking on the TextField and so that the back button appears on the left and the buttons disappear on the right?

code

TextFormField(
                style: constants.Styles.textFieldTextStyleWhite,
                cursorColor: Colors.white,
                decoration: InputDecoration(
                    contentPadding: const EdgeInsets.only(
                      top: 15, // HERE THE IMPORTANT PART
                    ),
                    border: InputBorder.none,
                    prefixIcon: Align(
                        alignment: Alignment.centerLeft,
                        child: SvgPicture.asset(
                          constants.Assets.search,
                          width: 20,
                          height: 20,
                        ))),
              )

1 Answer 1

2

Wrap everything into a StatefulWidget.

Then, when clicking the TextFormField, change the attributes of the StatefulWidget.

class YourPage extends StatefulWidget {
  _YourPageState createState() => _YourPageState();
}

class _YourPageState extends State<YourPage> {

  var myBool = false;
  
  // Initialize your Row-buttons here
  // ...

  void changeRow(){
    setState(() {
 
     // Hide or show Row-buttons here.   

     myBool = true;

    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
       child: Scaffold(
         body: Row(children:[

             myBool == true 
               ? Icon( ...)         // shows icon
               : SizedBox.shrink(), // shows nothing

             TextFormField( onTap: () => changeRow() ),

             // other BUTTONs here
         ])
       ),
    );
  }
}

There are a few possibilities for an AppBar to show Text or Buttons.

Check these examples:

https://www.fluttercampus.com/tutorial/10/flutter-appbar/

Sign up to request clarification or add additional context in comments.

7 Comments

And if the search bar is not in my appbar, but just on the page itself? Or is there no difference?
Not a big difference, instead of an AppBar just use a Row(children:[ ... ]). It boils down to the same approach.v See updated answer.
I can initialize the true/false variable and change the value on click and change the widget depending on the value
Tell me, if I need to open a page with a search by clicking on the Textfield, how can I implement it?
@Max By using a navigator and call it from inside the click-function. docs.flutter.dev/cookbook/navigation/navigation-basics
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.