flutter – Is it possible to make submit button from another class?

Issue

I am making instagram clone project.

I haven’t made it yet, but I wonder if this function is possible.
enter image description here

I want to make submit button on the appbar

I could find done button source in Keyboard but i want to make appbar submit button.

cuz Appbar submit button function seems to have to use the access method of another class.

So I want to learn that. Is it related gloabalkey? hm….so confused…..

I’d really appreciate it if anyone could help me out.

Solution

Yes You can do this :
You can use Getx for this to observe the EditText and when button click it will take the action as per the EditText.
Here is the Getx Example:

dependencies:
  get: ^4.6.1

Example:
In this example you will learn the basics of GetX. You will see how much easier it is to code with this framework, and you will know what problems GetX proposes to solve.

If the default Flutter application were rewritten with Getx, it would have only a few lines of code. The Getx state manager is easier than using setState. You just need to add a ".obs" at the end of your variable, and wrap the widget you want to change within a Obx().

void main() => runApp(MaterialApp(home: Home()));

class Home extends StatelessWidget {
  var count = 0.obs;
  @override
  Widget build(context) => Scaffold(
      appBar: AppBar(title: Text("counter")),
      body: Center(
        child: Obx(() => Text("$count")),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () => count ++,
      ));
}

hope its Helpful to you thanks

Answered By – Tasnuva Tavasum oshin

Answer Checked By – David Marino (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *