mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 08:20:36 +00:00
Add sensor contact preview sheet
This commit is contained in:
@@ -14,6 +14,7 @@ class AddContactScreen extends StatefulWidget {
|
|||||||
class _AddContactScreenState extends State<AddContactScreen> {
|
class _AddContactScreenState extends State<AddContactScreen> {
|
||||||
final TextEditingController _advertController = TextEditingController();
|
final TextEditingController _advertController = TextEditingController();
|
||||||
bool _isImporting = false;
|
bool _isImporting = false;
|
||||||
|
bool _importSucceeded = false;
|
||||||
String? _validationError;
|
String? _validationError;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -85,6 +86,7 @@ class _AddContactScreenState extends State<AddContactScreen> {
|
|||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_advertController.text = text.trim();
|
_advertController.text = text.trim();
|
||||||
|
_importSucceeded = false;
|
||||||
_validationError = null;
|
_validationError = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -110,6 +112,7 @@ class _AddContactScreenState extends State<AddContactScreen> {
|
|||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_isImporting = true;
|
_isImporting = true;
|
||||||
|
_importSucceeded = false;
|
||||||
_validationError = null;
|
_validationError = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -139,7 +142,9 @@ class _AddContactScreenState extends State<AddContactScreen> {
|
|||||||
ScaffoldMessenger.of(
|
ScaffoldMessenger.of(
|
||||||
context,
|
context,
|
||||||
).showSnackBar(const SnackBar(content: Text('Contact imported')));
|
).showSnackBar(const SnackBar(content: Text('Contact imported')));
|
||||||
Navigator.of(context).pop(true);
|
setState(() {
|
||||||
|
_importSucceeded = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -169,8 +174,9 @@ class _AddContactScreenState extends State<AddContactScreen> {
|
|||||||
minLines: 4,
|
minLines: 4,
|
||||||
maxLines: 8,
|
maxLines: 8,
|
||||||
onChanged: (_) {
|
onChanged: (_) {
|
||||||
if (_validationError != null) {
|
if (_validationError != null || _importSucceeded) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
_importSucceeded = false;
|
||||||
_validationError = null;
|
_validationError = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -204,19 +210,48 @@ class _AddContactScreenState extends State<AddContactScreen> {
|
|||||||
const SizedBox(width: 12),
|
const SizedBox(width: 12),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: FilledButton.icon(
|
child: FilledButton.icon(
|
||||||
onPressed: _isImporting ? null : _importContact,
|
onPressed: (_isImporting || _importSucceeded)
|
||||||
|
? null
|
||||||
|
: _importContact,
|
||||||
icon: _isImporting
|
icon: _isImporting
|
||||||
? const SizedBox(
|
? const SizedBox(
|
||||||
width: 16,
|
width: 16,
|
||||||
height: 16,
|
height: 16,
|
||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
)
|
)
|
||||||
|
: _importSucceeded
|
||||||
|
? const Icon(Icons.check_circle_outline)
|
||||||
: const Icon(Icons.person_add_alt_1_outlined),
|
: const Icon(Icons.person_add_alt_1_outlined),
|
||||||
label: Text(_isImporting ? 'Importing...' : 'Add Contact'),
|
label: Text(
|
||||||
|
_isImporting
|
||||||
|
? 'Importing...'
|
||||||
|
: _importSucceeded
|
||||||
|
? 'Added'
|
||||||
|
: 'Add Contact',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
if (_importSucceeded) ...[
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.check_circle,
|
||||||
|
size: 18,
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Text(
|
||||||
|
'Contact added. Paste or edit another advert to import again.',
|
||||||
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user