mirrored_repositories/AIRPA-App/lib/modules/profile
import 'package:flutter/material.dart';
import 'package:string_validator/string_validator.dart';
import 'package:penyewaan_gedung_app/widgets/appbar_widget.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:penyewaan_gedung_app/widgets/common_button.dart';
import 'package:penyewaan_gedung_app/modules/admin/users/db_services.dart';
import 'package:penyewaan_gedung_app/models/user_model.dart';

// This class handles the Page to edit the Phone Section of the User Profile.
class EditPhoneFormPage extends StatefulWidget {
  final UserModel? userModel;
  const EditPhoneFormPage({Key? key, this.userModel}) : super(key: key);

  @override
  EditPhoneFormPageState createState() {
    return EditPhoneFormPageState();
  }
}

class EditPhoneFormPageState extends State<EditPhoneFormPage> {
  final _formKey = GlobalKey<FormState>();
  final _phoneController = TextEditingController();

  int _jumlah = 0;

  User? user = FirebaseAuth.instance.currentUser;

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: buildAppBar(context),
        body: Form(
          key: _formKey,
          child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                const SizedBox(
                    width: 320,
                    child: Text(
                      "Masukan nomer hp",
                      style:
                          TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
                    )),
                Padding(
                    padding: const EdgeInsets.only(top: 40),
                    child: SizedBox(
                        height: 100,
                        width: 320,
                        child: TextFormField(
                          // Handles Form Validation
                          validator: (value) {
                            if (value == null || value.isEmpty) {
                              return 'Silakan masukkan nomor telepon Anda';
                            } else if (isAlpha(value)) {
                              return 'Hanya Nomor Silahkan';
                            } else if (value.length < 11) {
                              return 'Silakan masukkan nomor telepon yang VALID';
                            }
                            return null;
                          },
                          controller: _phoneController,
                          decoration: const InputDecoration(
                            labelText: 'Nomer hp kamu',
                          ),
                        ))),
                Padding(
                    padding: const EdgeInsets.only(top: 150),
                    child: Align(
                        alignment: Alignment.bottomCenter,
                        child: SizedBox(
                          width: 320,
                          height: 50,
                          child: CommonButton(
                              padding: const EdgeInsets.only(
                                  left: 24, right: 24, bottom: 8),
                              buttonText: "Update",
                              onTap: () {
                                _jumlah++;
                                final dt =
                                    UserModel(phone: _phoneController.hashCode);
                                Database.ubahData(ubahUser: dt);
                                Navigator.pop(context);
                              }),
                        )))
              ]),
        ));
  }
}
