@ -1,11 +1,158 @@
import ' package:diplomaticquarterapp/core/viewModels/project_view_model.dart ' ;
import ' package:diplomaticquarterapp/models/mobile_number.dart ' ;
import ' package:diplomaticquarterapp/uitl/translations_delegate_base.dart ' ;
import ' package:flutter/cupertino.dart ' ;
import ' package:flutter/material.dart ' ;
import ' package:provider/provider.dart ' ;
import ' ../../Constants.dart ' ;
class PhoneNumberSelectorWidget extends StatefulWidget {
final Function onNumberChange ;
final Function onCountryChange ;
PhoneNumberSelectorWidget ( {
Key key ,
this . onNumberChange ,
this . onCountryChange ,
} ) : super ( key: key ) ;
@ override
_PhoneNumberSelectorWidgetState createState ( ) {
return _PhoneNumberSelectorWidgetState ( ) ;
}
}
class _PhoneNumberSelectorWidgetState extends State < PhoneNumberSelectorWidget > {
var _selectedType = ' +966 ' ;
String countryCode = ' +966 ' ;
List < Countries > counties = [ ] ;
ProjectViewModel projectProvider ;
@ override
void initState ( ) {
for ( var element in countriesData ) counties . add ( Countries . fromJson ( element ) ) ;
super . initState ( ) ;
}
@ override
void dispose ( ) {
super . dispose ( ) ;
}
@ override
Widget build ( BuildContext context ) {
projectProvider = Provider . of ( context ) ;
String countryName = " " ;
for ( var element in counties ) {
if ( element . code = = countryCode ) {
countryName = projectProvider . isArabic = = true ? element . nameAr : element . name ;
}
}
return Column (
children: [
inputWidget ( TranslationBase . of ( context ) . country , countryName , isEnable: false , hasSelection: true ) ,
SizedBox ( height: 12 ) ,
inputWidget ( TranslationBase . of ( context ) . phoneNumber , " 5xxxxxxxx " , prefix: countryCode ) ,
] ,
) ;
}
Widget inputWidget ( String _labelText , String _hintText , { String prefix , bool isEnable = true , bool hasSelection = false } ) {
return Container (
padding: EdgeInsets . only ( left: 16 , right: 16 , bottom: 15 , top: 15 ) ,
alignment: Alignment . center ,
decoration: BoxDecoration (
borderRadius: BorderRadius . circular ( 15 ) ,
color: Colors . white ,
border: Border . all (
color: Color ( 0xffefefef ) ,
width: 1 ,
) ,
) ,
child: PopupMenuButton (
tooltip: " " ,
child: Row (
children: [
Expanded (
child: Column (
mainAxisSize: MainAxisSize . min ,
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
Text (
_labelText ,
style: TextStyle (
fontSize: 11 ,
fontFamily: " Poppins " ,
fontWeight: FontWeight . w600 ,
color: Color ( 0xff2B353E ) ,
letterSpacing: - 0.44 ,
) ,
) ,
TextField (
enabled: isEnable ,
scrollPadding: EdgeInsets . zero ,
keyboardType: TextInputType . number ,
onChanged: ( value ) = > widget . onNumberChange ( value ) ,
style: TextStyle (
fontSize: 14 ,
fontFamily: " Poppins " ,
height: 21 / 14 ,
fontWeight: FontWeight . w400 ,
color: Color ( 0xff2B353E ) ,
letterSpacing: - 0.44 ,
) ,
decoration: InputDecoration (
isDense: true ,
hintText: _hintText ,
hintStyle: TextStyle (
fontSize: 14 ,
fontFamily: " Poppins " ,
height: 21 / 14 ,
fontWeight: FontWeight . w400 ,
color: Color ( 0xff575757 ) ,
letterSpacing: - 0.56 ,
) ,
prefixIconConstraints: BoxConstraints ( minWidth: 50 ) ,
prefixIcon: prefix = = null
? null
: Text (
prefix ,
style: TextStyle (
fontSize: 14 ,
fontFamily: " Poppins " ,
height: 21 / 14 ,
fontWeight: FontWeight . w500 ,
color: Color ( 0xff2E303A ) ,
letterSpacing: - 0.56 ,
) ,
) ,
contentPadding: EdgeInsets . zero ,
border: InputBorder . none ,
focusedBorder: InputBorder . none ,
enabledBorder: InputBorder . none ,
) ,
) ,
] ,
) ,
) ,
if ( hasSelection ) Icon ( Icons . keyboard_arrow_down_outlined ) ,
] ,
) ,
itemBuilder: ( _ ) = > < PopupMenuItem < String > > [
if ( hasSelection )
for ( var country in counties ) PopupMenuItem < String > ( child: Text ( projectProvider . isArabic = = true ? country . nameAr : country . name ) , value: country . code )
] ,
onSelected: ( countryCode ) {
setState ( ( ) {
this . countryCode = countryCode ;
_selectedType = countryCode ;
} ) ;
widget . onCountryChange ( countryCode ) ;
} ,
) ) ;
}
}
class MobileNo extends StatefulWidget {
final bool disabled ;
@ -18,16 +165,7 @@ class MobileNo extends StatefulWidget {
final Function onNumberChange ;
final Function onCountryChange ;
MobileNo (
{ this . disabled = false ,
this . marginTop = 0 ,
this . marginRight = 0 ,
this . marginBottom = 0 ,
this . controller ,
this . marginLeft = 0 ,
this . onNumberChange ,
this . onCountryChange ,
this . margin = 0 } ) ;
MobileNo ( { this . disabled = false , this . marginTop = 0 , this . marginRight = 0 , this . marginBottom = 0 , this . controller , this . marginLeft = 0 , this . onNumberChange , this . onCountryChange , this . margin = 0 } ) ;
@ override
_MobileNo createState ( ) = > _MobileNo ( ) ;
@ -82,13 +220,10 @@ class _MobileNo extends State<MobileNo> {
_selectedType = value ;
} )
} ,
items: counties . map < DropdownMenuItem < String > > (
( Countries value ) {
items: counties . map < DropdownMenuItem < String > > ( ( Countries value ) {
return DropdownMenuItem < String > (
value: value . code ,
child: Text ( projectProvider . isArabic = = true
? value . nameAr
: value . name ) ,
child: Text ( projectProvider . isArabic = = true ? value . nameAr : value . name ) ,
) ;
} ) . toList ( ) ) ) ) ) ,
) ,
@ -96,10 +231,7 @@ class _MobileNo extends State<MobileNo> {
) ,
Container (
padding: EdgeInsets . all ( 5 ) ,
decoration: BoxDecoration (
color: Colors . white ,
border: Border . all ( color: Colors . grey ) ,
borderRadius: BorderRadius . circular ( 10 ) ) ,
decoration: BoxDecoration ( color: Colors . white , border: Border . all ( color: Colors . grey ) , borderRadius: BorderRadius . circular ( 10 ) ) ,
child: Row ( children: < Widget > [
Expanded (
flex: 1 ,
@ -116,13 +248,7 @@ class _MobileNo extends State<MobileNo> {
Expanded (
flex: 4 ,
child: Container (
margin: widget . margin ! = null
? EdgeInsets . all ( widget . margin )
: EdgeInsets . only (
top: widget . marginTop ,
right: widget . marginRight ,
bottom: widget . marginBottom ,
left: widget . marginLeft ) ,
margin: widget . margin ! = null ? EdgeInsets . all ( widget . margin ) : EdgeInsets . only ( top: widget . marginTop , right: widget . marginRight , bottom: widget . marginBottom , left: widget . marginLeft ) ,
child: TextField (
controller: widget . controller ,
keyboardType: TextInputType . number ,
@ -134,10 +260,7 @@ class _MobileNo extends State<MobileNo> {
/ / } ,
onChanged: ( value ) = > widget . onNumberChange ( value ) ,
decoration: InputDecoration (
counterText: " " ,
border: InputBorder . none ,
hintText: ' 5xxxxxxxx ' ) ,
decoration: InputDecoration ( counterText: " " , border: InputBorder . none , hintText: ' 5xxxxxxxx ' ) ,
) ,
) ,
)