@@ -39,6 +39,7 @@ class _AddEditContactState extends State<AddEditContact> {
3939 bool saveLoading = false ;
4040 String ? nameError;
4141 String ? addressError;
42+ ChainType ? _selectedChainType;
4243 Future <void > _showDialog (
4344 String title, String message, IconData icon, DialogType type) async {
4445 showDialog (
@@ -94,11 +95,12 @@ class _AddEditContactState extends State<AddEditContact> {
9495
9596 return false ;
9697 }
97- if (widget.chainType == ChainType .TFChain && contactAddress.length != 48 ) {
98+ if (_selectedChainType == ChainType .TFChain &&
99+ contactAddress.length != 48 ) {
98100 addressError = 'Address length should be 48 characters' ;
99101 return false ;
100102 }
101- if (widget.chainType == ChainType .Stellar &&
103+ if (_selectedChainType == ChainType .Stellar &&
102104 ! isValidStellarAddress (contactAddress)) {
103105 addressError = 'Invaild Stellar address' ;
104106 return false ;
@@ -107,8 +109,11 @@ class _AddEditContactState extends State<AddEditContact> {
107109 }
108110
109111 _add (String contactName, String contactAddress) async {
112+ final chainType = _selectedChainType == ChainType .Stellar
113+ ? ChainType .Stellar
114+ : ChainType .TFChain ;
110115 try {
111- await addContact (contactName, contactAddress, widget. chainType);
116+ await addContact (contactName, contactAddress, chainType);
112117 await _showDialog (
113118 'Contact Added!' ,
114119 'Contact $contactName has been added successfully' ,
@@ -120,8 +125,10 @@ class _AddEditContactState extends State<AddEditContact> {
120125 Icons .error, DialogType .Error );
121126 return ;
122127 }
123- widget.onAddContact !(PkidContact (
124- name: contactName, address: contactAddress, type: widget.chainType));
128+ if (chainType == widget.chainType) {
129+ widget.onAddContact !(PkidContact (
130+ name: contactName, address: contactAddress, type: chainType));
131+ }
125132 if (! context.mounted) return ;
126133 Navigator .pop (context);
127134 }
@@ -183,6 +190,7 @@ class _AddEditContactState extends State<AddEditContact> {
183190 _nameController.text = widget.name;
184191 _addressController.text = widget.address;
185192 }
193+ _selectedChainType = widget.chainType;
186194 super .initState ();
187195 }
188196
@@ -232,9 +240,47 @@ class _AddEditContactState extends State<AddEditContact> {
232240 ),
233241 controller: _addressController,
234242 ),
235- const SizedBox (
236- height: 30 ,
237- ),
243+ const SizedBox (height: 20 ),
244+ if (widget.operation == ContactOperation .Add )
245+ Row (
246+ children: [
247+ Text (
248+ 'Chain Type:' ,
249+ style: Theme .of (context).textTheme.bodyMedium! .copyWith (
250+ color: Theme .of (context).colorScheme.onSurface,
251+ decorationColor:
252+ Theme .of (context).colorScheme.onSurface),
253+ ),
254+ const SizedBox (width: 10 ),
255+ DropdownButton <ChainType >(
256+ value: _selectedChainType,
257+ onChanged: (ChainType ? newValue) {
258+ setState (() {
259+ _selectedChainType = newValue! ;
260+ });
261+ },
262+ items: ChainType .values
263+ .map <DropdownMenuItem <ChainType >>((ChainType type) {
264+ return DropdownMenuItem <ChainType >(
265+ value: type,
266+ child: Text (
267+ type.name,
268+ style: Theme .of (context)
269+ .textTheme
270+ .bodyMedium!
271+ .copyWith (
272+ color:
273+ Theme .of (context).colorScheme.onSurface,
274+ decorationColor:
275+ Theme .of (context).colorScheme.onSurface,
276+ ),
277+ ),
278+ );
279+ }).toList (),
280+ ),
281+ ],
282+ ),
283+ const SizedBox (height: 30 ),
238284 Row (
239285 children: [
240286 const Spacer (),
@@ -244,9 +290,7 @@ class _AddEditContactState extends State<AddEditContact> {
244290 Navigator .pop (context);
245291 },
246292 child: const Text ('Close' )),
247- const SizedBox (
248- width: 5 ,
249- ),
293+ const SizedBox (width: 5 ),
250294 ElevatedButton (
251295 onPressed: widget.operation == ContactOperation .Add
252296 ? _validateAndAdd
0 commit comments