Khan Wahidulhaq
Khan Wahidulhaq

Reputation: 1

How the get specific user details from the user id in flutter

I have voter id api and I want show the show specific voter details input from the textfield eg if the user put in text field voter name and voter show the all details in next page specific voteruser details

Upvotes: 0

Views: 421

Answers (1)

Gabriele Feudo
Gabriele Feudo

Reputation: 59

1. Create a TextEditController, which is a class you can link to the input field to get the text inside it (it’s good practice to put it inside a StatefulWidget, in this way we can dispose it):

// Define a custom Form widget.
class MyCustomForm extends StatefulWidget {
  const MyCustomForm({Key? key}) : super(key: key);

  @override
  _MyCustomFormState createState() => _MyCustomFormState();
}

// Define a corresponding State class.
// This class holds the data related to the Form.
class _MyCustomFormState extends State<MyCustomForm> {
  // Create a text controller and use it to retrieve the current value
  // of the TextField.
  final myController = TextEditingController();

  @override
  void dispose() {
    // Clean up the controller when the widget is disposed.
    myController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // Fill this out in the next step.
  }
}

2. Link the controller with your text field:

TextField(
  controller: myController,
);

3. Get text with:

myController.text

4. Implementing Navigator class, send data as argument of your next page following the official documentation:

Upvotes: 1

Related Questions