You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/widgets/mobile-no/mobile_no.dart

127 lines
4.0 KiB
Dart

4 years ago
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
// OWNER : Ibrahim albitar
// DATE : 12-04-2020
// DESCRIPTION : Customization for Texts in app
class MobileNo extends StatefulWidget {
final bool disabled;
// final String data;
4 years ago
final List<Countries> countries = [
new Countries(name: 'Saudi Arabia', code: '966'),
new Countries(name: 'Dubai', code: '971'),
];
4 years ago
final double margin;
final double marginTop;
final double marginRight;
final double marginBottom;
final double marginLeft;
final TextEditingController controller;
4 years ago
final Function onNumberChange;
final Function onCountryChange;
4 years ago
MobileNo(
{this.disabled = false,
this.marginTop = 0,
this.marginRight = 0,
this.marginBottom = 0,
this.controller,
this.marginLeft = 0,
4 years ago
this.onNumberChange,
this.onCountryChange,
4 years ago
this.margin = 0});
@override
_MobileNo createState() => _MobileNo();
}
class _MobileNo extends State<MobileNo> {
4 years ago
var _selectedType = '966';
String countryCode = '966';
4 years ago
@override
Widget build(BuildContext context) {
return Visibility(
4 years ago
child: Column(children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
// add Expanded to have your dropdown button fill remaining space
child: Padding(
padding: EdgeInsets.all(10),
child: DropdownButtonHideUnderline(
child: DropdownButton(
isExpanded: true,
value: _selectedType,
iconSize: 40,
elevation: 16,
4 years ago
onChanged: (value) => {
widget.onCountryChange(value),
setState(() {
countryCode = value;
_selectedType = value;
})
},
items: widget.countries
.map<DropdownMenuItem<String>>((Countries value) {
4 years ago
return DropdownMenuItem<String>(
4 years ago
value: value.code,
child: Text(value.name),
4 years ago
);
}).toList())))),
],
),
Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
4 years ago
color: Colors.white,
4 years ago
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(10)),
child: Row(children: <Widget>[
Expanded(
flex: 1,
child: Icon(
Icons.phone,
color: Color(0xFF40ACC9),
4 years ago
)),
Expanded(
flex: 1,
child: Text(
4 years ago
countryCode,
4 years ago
overflow: TextOverflow.clip,
4 years ago
4 years ago
)),
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),
child: TextField(
controller: widget.controller,
4 years ago
keyboardType: TextInputType.phone,
// onChanged: (value) {
// widget.controller.text = countryCode;
// },
onChanged: (value) => widget.onNumberChange(value),
4 years ago
decoration: InputDecoration(
border: InputBorder.none, hintText: '5xxxxxxxx'),
),
4 years ago
),
4 years ago
)
]),
)
]));
4 years ago
}
}
4 years ago
class Countries {
final String name;
final String code;
Countries({this.name, this.code});
}