import 'package:mobdr/config/constant.dart'; import 'package:mobdr/config/global_style.dart'; import 'package:mobdr/ui/reusable/reusable_widget.dart'; import 'package:mobdr/ui/reusable/global_function.dart'; import 'package:flutter/material.dart'; class EditPhoneNumberPage extends StatefulWidget { @override _EditPhoneNumberPageState createState() => _EditPhoneNumberPageState(); } class _EditPhoneNumberPageState extends State { // initialize reusable widget and global function final _reusableWidget = ReusableWidget(); final _globalFunction = GlobalFunction(); TextEditingController _etPhoneNumber = TextEditingController(); bool _buttonDisabled = true; @override void initState() { _etPhoneNumber = TextEditingController(text: '0811888999'); if (_globalFunction.validateMobileNumber(_etPhoneNumber.text)) { _buttonDisabled = false; } else { _buttonDisabled = true; } super.initState(); } @override void dispose() { _etPhoneNumber.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( iconTheme: IconThemeData( color: GlobalStyle.appBarIconThemeColor, ), elevation: GlobalStyle.appBarElevation, title: Text( 'Edit Phone Number', style: GlobalStyle.appBarTitle, ), backgroundColor: GlobalStyle.appBarBackgroundColor, systemOverlayStyle: GlobalStyle.appBarSystemOverlayStyle, bottom: _reusableWidget.bottomAppBar(), ), body: ListView( padding: EdgeInsets.all(16), children: [ TextFormField( keyboardType: TextInputType.number, controller: _etPhoneNumber, style: TextStyle(color: CHARCOAL), onChanged: (textValue) { setState(() { if (_globalFunction.validateMobileNumber(textValue)) { _buttonDisabled = false; } else { _buttonDisabled = true; } }); }, decoration: InputDecoration( focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: PRIMARY_COLOR, width: 2.0)), enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: Color(0xFFCCCCCC)), ), labelText: 'Phone Number', labelStyle: TextStyle(color: BLACK_GREY)), ), SizedBox( height: 40, ), Container( child: TextButton( style: ButtonStyle( backgroundColor: MaterialStateProperty.resolveWith( (Set states) => states.contains(MaterialState.disabled) ? Colors.grey[300]! : _buttonDisabled ? Colors.grey[300]! : PRIMARY_COLOR, ), overlayColor: MaterialStateProperty.all(Colors.transparent), shape: MaterialStateProperty.all(RoundedRectangleBorder( borderRadius: BorderRadius.circular(3.0), )), ), onPressed: () { if (!_buttonDisabled) { _reusableWidget.startLoading( context, 'Edit Phone Number Success', 1); FocusScope.of(context).unfocus(); } }, child: Padding( padding: const EdgeInsets.symmetric(vertical: 5), child: Text( 'Save', style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, color: _buttonDisabled ? Colors.grey[600] : Colors.white), textAlign: TextAlign.center, ), )), ), ], )); } }