How can I save user information using uid in real-time database using flutter?

Viewed 17

I am working on saving car details of the user on real-time firebase but having difficulties. Any assistance is highly appreciated. Below is the sample of the code that I am working on. It has two dropdown buttons that are depended on each other and store vital information on the car model and make of the user.

 return Scaffold(
      appBar: AppBar(
        title: const Text('Car Type'),
        centerTitle: true,
      ),
      body: SingleChildScrollView(
        key: _formKeyValue,
        // autovalidateMode: AutovalidateMode.always,
        child: Column(
          children: <Widget>[
            const SizedBox(
              height: 10,
            ),
            DropdownButton<String?>(
              value: selectedCarModel,
              items: dataset.keys.map((e) {
                return DropdownMenuItem<String?>(
                  value: e,
                  child: Text(e),
                );
              }).toList(),
              onChanged: onCarModelChanged,
              hint: const Text('car model'),
            ),

            const SizedBox(
              height: 10,
            ),
            DropdownButton<String?>(
                value: selectedCarMake,
                hint: const Text('car make'),
                items: (dataset[selectedCarModel] ?? []).map((e) {
                  return DropdownMenuItem<String?>(
                    value: e,
                    child: Text(e),
                  );
                }).toList(),
                onChanged: (val) {
                  setState(() {
                    selectedCarMake = val!;
                  });
                }),

            const SizedBox(
              height: 10,
            ),
            // year textfield
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: TextFormField(
                controller: _yearController,
                enableSuggestions: false,
                keyboardType: TextInputType.number,
                decoration: InputDecoration(
                  hintText: 'Year',
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(10),
                    borderSide: const BorderSide(color: Colors.orange),
                  ),
                ),
              ),
            ),
            //space in between the two fields
            const SizedBox(
              height: 10,
            ),
            //applied model textfield
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: TextFormField(
                controller: _appModelController,
                enableSuggestions: false,
                keyboardType: TextInputType.name,
                decoration: InputDecoration(
                  hintText: 'Applied Model',
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(10),
                    borderSide: const BorderSide(color: Colors.deepOrange),
                  ),
                ),
              ),
            ),
            const SizedBox(
              height: 10,
            ),
            //numberplate textfield
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: TextFormField(
                controller: _numberPlateController,
                enableSuggestions: false,
                decoration: InputDecoration(
                  hintText: 'Number Plate',
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(10),
                    borderSide: const BorderSide(color: Colors.deepOrange),
                  ),
                ),
              ),
            ),
            const SizedBox(
              height: 10,
            ),
            //add car textbutton
            ElevatedButton(
              onPressed: () {
                if (_yearController.text.isNotEmpty &&
                    _appModelController.text.isNotEmpty &&
                    _numberPlateController.text.isNotEmpty) {
                  insertData(
                    _yearController.text,
                    _appModelController.text,
                    _numberPlateController.text,
                  );
                }
              },
              child: const Text('ADD CAR'),
            ),
0 Answers
Related