mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-20 14:19:07 +00:00
desktop add new contact address entry
This commit is contained in:
parent
cd19d776ae
commit
df64e48e1e
3 changed files with 213 additions and 180 deletions
|
@ -12,7 +12,11 @@ import 'package:stackwallet/utilities/barcode_scanner_interface.dart';
|
||||||
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||||
|
import 'package:stackwallet/utilities/util.dart';
|
||||||
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||||
|
import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
||||||
|
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
||||||
|
|
||||||
class AddNewContactAddressView extends ConsumerStatefulWidget {
|
class AddNewContactAddressView extends ConsumerStatefulWidget {
|
||||||
const AddNewContactAddressView({
|
const AddNewContactAddressView({
|
||||||
|
@ -55,190 +59,170 @@ class _AddNewContactAddressViewState
|
||||||
final contact = ref.watch(addressBookServiceProvider
|
final contact = ref.watch(addressBookServiceProvider
|
||||||
.select((value) => value.getContactById(contactId)));
|
.select((value) => value.getContactById(contactId)));
|
||||||
|
|
||||||
return Scaffold(
|
final isDesktop = Util.isDesktop;
|
||||||
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
|
|
||||||
appBar: AppBar(
|
return ConditionalParent(
|
||||||
leading: AppBarBackButton(
|
condition: !isDesktop,
|
||||||
onPressed: () async {
|
builder: (child) => Scaffold(
|
||||||
if (FocusScope.of(context).hasFocus) {
|
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
|
||||||
FocusScope.of(context).unfocus();
|
appBar: AppBar(
|
||||||
await Future<void>.delayed(const Duration(milliseconds: 75));
|
leading: AppBarBackButton(
|
||||||
}
|
onPressed: () async {
|
||||||
if (mounted) {
|
if (FocusScope.of(context).hasFocus) {
|
||||||
Navigator.of(context).pop();
|
FocusScope.of(context).unfocus();
|
||||||
}
|
await Future<void>.delayed(const Duration(milliseconds: 75));
|
||||||
},
|
}
|
||||||
|
if (mounted) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
"Add new address",
|
||||||
|
style: STextStyles.navBarTitle(context),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
title: Text(
|
body: LayoutBuilder(
|
||||||
"Add new address",
|
builder: (context, constraints) {
|
||||||
style: STextStyles.navBarTitle(context),
|
return Padding(
|
||||||
),
|
padding: const EdgeInsets.only(
|
||||||
),
|
left: 12,
|
||||||
body: LayoutBuilder(
|
top: 12,
|
||||||
builder: (context, constraints) {
|
right: 12,
|
||||||
return Padding(
|
),
|
||||||
padding: const EdgeInsets.only(
|
child: SingleChildScrollView(
|
||||||
left: 12,
|
child: ConstrainedBox(
|
||||||
top: 12,
|
constraints: BoxConstraints(
|
||||||
right: 12,
|
minHeight: constraints.maxHeight - 24,
|
||||||
),
|
),
|
||||||
child: SingleChildScrollView(
|
child: IntrinsicHeight(
|
||||||
child: ConstrainedBox(
|
child: Padding(
|
||||||
constraints: BoxConstraints(
|
padding: const EdgeInsets.all(4),
|
||||||
minHeight: constraints.maxHeight - 24,
|
child: child,
|
||||||
),
|
|
||||||
child: IntrinsicHeight(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(4),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
height: 48,
|
|
||||||
width: 48,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(24),
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.textFieldActiveBG,
|
|
||||||
),
|
|
||||||
child: Center(
|
|
||||||
child: contact.emojiChar == null
|
|
||||||
? SvgPicture.asset(
|
|
||||||
Assets.svg.user,
|
|
||||||
height: 24,
|
|
||||||
width: 24,
|
|
||||||
)
|
|
||||||
: Text(
|
|
||||||
contact.emojiChar!,
|
|
||||||
style: STextStyles.pageTitleH1(context),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
width: 16,
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: FittedBox(
|
|
||||||
fit: BoxFit.scaleDown,
|
|
||||||
child: Text(
|
|
||||||
contact.name,
|
|
||||||
style: STextStyles.pageTitleH2(context),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 16,
|
|
||||||
),
|
|
||||||
NewContactAddressEntryForm(
|
|
||||||
id: 0,
|
|
||||||
barcodeScanner: barcodeScanner,
|
|
||||||
clipboard: clipboard,
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 16,
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: TextButton(
|
|
||||||
style: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.getSecondaryEnabledButtonColor(context),
|
|
||||||
child: Text(
|
|
||||||
"Cancel",
|
|
||||||
style: STextStyles.button(context).copyWith(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.accentColorDark),
|
|
||||||
),
|
|
||||||
onPressed: () async {
|
|
||||||
if (FocusScope.of(context).hasFocus) {
|
|
||||||
FocusScope.of(context).unfocus();
|
|
||||||
await Future<void>.delayed(
|
|
||||||
const Duration(milliseconds: 75));
|
|
||||||
}
|
|
||||||
if (mounted) {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
width: 16,
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Builder(
|
|
||||||
builder: (context) {
|
|
||||||
bool shouldEnableSave =
|
|
||||||
ref.watch(validContactStateProvider([0]));
|
|
||||||
|
|
||||||
return TextButton(
|
|
||||||
style: shouldEnableSave
|
|
||||||
? Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.getPrimaryEnabledButtonColor(
|
|
||||||
context)
|
|
||||||
: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.getPrimaryDisabledButtonColor(
|
|
||||||
context),
|
|
||||||
onPressed: shouldEnableSave
|
|
||||||
? () async {
|
|
||||||
if (FocusScope.of(context)
|
|
||||||
.hasFocus) {
|
|
||||||
FocusScope.of(context).unfocus();
|
|
||||||
await Future<void>.delayed(
|
|
||||||
const Duration(
|
|
||||||
milliseconds: 75),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
List<ContactAddressEntry> entries =
|
|
||||||
contact.addresses;
|
|
||||||
|
|
||||||
entries.add(ref
|
|
||||||
.read(
|
|
||||||
addressEntryDataProvider(0))
|
|
||||||
.buildAddressEntry());
|
|
||||||
|
|
||||||
Contact editedContact = contact
|
|
||||||
.copyWith(addresses: entries);
|
|
||||||
|
|
||||||
if (await ref
|
|
||||||
.read(
|
|
||||||
addressBookServiceProvider)
|
|
||||||
.editContact(editedContact)) {
|
|
||||||
if (mounted) {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}
|
|
||||||
// TODO show success notification
|
|
||||||
} else {
|
|
||||||
// TODO show error notification
|
|
||||||
}
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
child: Text(
|
|
||||||
"Save",
|
|
||||||
style: STextStyles.button(context),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
},
|
||||||
},
|
),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
height: 48,
|
||||||
|
width: 48,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(24),
|
||||||
|
color: Theme.of(context)
|
||||||
|
.extension<StackColors>()!
|
||||||
|
.textFieldActiveBG,
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: contact.emojiChar == null
|
||||||
|
? SvgPicture.asset(
|
||||||
|
Assets.svg.user,
|
||||||
|
height: 24,
|
||||||
|
width: 24,
|
||||||
|
)
|
||||||
|
: Text(
|
||||||
|
contact.emojiChar!,
|
||||||
|
style: STextStyles.pageTitleH1(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
width: 16,
|
||||||
|
),
|
||||||
|
if (isDesktop)
|
||||||
|
Text(
|
||||||
|
contact.name,
|
||||||
|
style: STextStyles.pageTitleH2(context),
|
||||||
|
),
|
||||||
|
if (!isDesktop)
|
||||||
|
Expanded(
|
||||||
|
child: FittedBox(
|
||||||
|
fit: BoxFit.scaleDown,
|
||||||
|
child: Text(
|
||||||
|
contact.name,
|
||||||
|
style: STextStyles.pageTitleH2(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 16,
|
||||||
|
),
|
||||||
|
NewContactAddressEntryForm(
|
||||||
|
id: 0,
|
||||||
|
barcodeScanner: barcodeScanner,
|
||||||
|
clipboard: clipboard,
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 16,
|
||||||
|
),
|
||||||
|
const Spacer(),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: SecondaryButton(
|
||||||
|
label: "Cancel",
|
||||||
|
buttonHeight: isDesktop ? ButtonHeight.l : null,
|
||||||
|
onPressed: () async {
|
||||||
|
if (!isDesktop && FocusScope.of(context).hasFocus) {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
await Future<void>.delayed(
|
||||||
|
const Duration(milliseconds: 75));
|
||||||
|
}
|
||||||
|
if (mounted) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
width: 16,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: PrimaryButton(
|
||||||
|
label: "Save",
|
||||||
|
enabled: ref.watch(validContactStateProvider([0])),
|
||||||
|
buttonHeight: isDesktop ? ButtonHeight.l : null,
|
||||||
|
onPressed: () async {
|
||||||
|
if (FocusScope.of(context).hasFocus) {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
await Future<void>.delayed(
|
||||||
|
const Duration(milliseconds: 75),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
List<ContactAddressEntry> entries = contact.addresses;
|
||||||
|
|
||||||
|
entries.add(ref
|
||||||
|
.read(addressEntryDataProvider(0))
|
||||||
|
.buildAddressEntry());
|
||||||
|
|
||||||
|
Contact editedContact =
|
||||||
|
contact.copyWith(addresses: entries);
|
||||||
|
|
||||||
|
if (await ref
|
||||||
|
.read(addressBookServiceProvider)
|
||||||
|
.editContact(editedContact)) {
|
||||||
|
if (mounted) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
// TODO show success notification
|
||||||
|
} else {
|
||||||
|
// TODO show error notification
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,8 @@ class DesktopAddressCard extends StatelessWidget {
|
||||||
return BlueTextButton(
|
return BlueTextButton(
|
||||||
text: "Edit",
|
text: "Edit",
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
ref.refresh(
|
||||||
|
addressEntryDataProviderFamilyRefresher);
|
||||||
ref.read(addressEntryDataProvider(0)).address =
|
ref.read(addressEntryDataProvider(0)).address =
|
||||||
entry.address;
|
entry.address;
|
||||||
ref.read(addressEntryDataProvider(0)).addressLabel =
|
ref.read(addressEntryDataProvider(0)).addressLabel =
|
||||||
|
|
|
@ -3,14 +3,18 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:stackwallet/models/contact.dart';
|
import 'package:stackwallet/models/contact.dart';
|
||||||
import 'package:stackwallet/models/paymint/transactions_model.dart';
|
import 'package:stackwallet/models/paymint/transactions_model.dart';
|
||||||
|
import 'package:stackwallet/pages/address_book_views/subviews/add_new_contact_address_view.dart';
|
||||||
import 'package:stackwallet/pages_desktop_specific/home/address_book_view/subwidgets/desktop_address_card.dart';
|
import 'package:stackwallet/pages_desktop_specific/home/address_book_view/subwidgets/desktop_address_card.dart';
|
||||||
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
|
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
|
||||||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||||
|
import 'package:stackwallet/providers/ui/address_book_providers/address_entry_data_provider.dart';
|
||||||
import 'package:stackwallet/services/coins/manager.dart';
|
import 'package:stackwallet/services/coins/manager.dart';
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||||
|
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||||
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
|
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
|
||||||
|
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
|
||||||
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
||||||
import 'package:stackwallet/widgets/loading_indicator.dart';
|
import 'package:stackwallet/widgets/loading_indicator.dart';
|
||||||
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
||||||
|
@ -154,7 +158,50 @@ class _DesktopContactDetailsState extends ConsumerState<DesktopContactDetails> {
|
||||||
),
|
),
|
||||||
BlueTextButton(
|
BlueTextButton(
|
||||||
text: "Add new",
|
text: "Add new",
|
||||||
onTap: () {},
|
onTap: () async {
|
||||||
|
ref.refresh(
|
||||||
|
addressEntryDataProviderFamilyRefresher);
|
||||||
|
|
||||||
|
await showDialog<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => DesktopDialog(
|
||||||
|
maxWidth: 580,
|
||||||
|
maxHeight: 566,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
const SizedBox(
|
||||||
|
width: 8,
|
||||||
|
),
|
||||||
|
const AppBarBackButton(
|
||||||
|
isCompact: true,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
"Add new address",
|
||||||
|
style:
|
||||||
|
STextStyles.desktopH3(context),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
top: 20,
|
||||||
|
left: 32,
|
||||||
|
right: 32,
|
||||||
|
bottom: 32,
|
||||||
|
),
|
||||||
|
child: AddNewContactAddressView(
|
||||||
|
contactId: widget.contactId,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue