2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-03-07 17:11:57 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
import 'package:stackwallet/pages/generic/single_field_edit_view.dart';
|
2023-05-09 21:57:40 +00:00
|
|
|
import 'package:stackwallet/themes/stack_colors.dart';
|
2023-03-07 17:11:57 +00:00
|
|
|
import 'package:stackwallet/utilities/assets.dart';
|
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2023-03-13 23:09:14 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
2023-03-07 17:11:57 +00:00
|
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
|
2023-03-13 23:09:14 +00:00
|
|
|
import '../desktop/desktop_dialog.dart';
|
|
|
|
import '../icon_widgets/pencil_icon.dart';
|
|
|
|
|
2023-03-07 17:11:57 +00:00
|
|
|
class SimpleEditButton extends StatelessWidget {
|
|
|
|
const SimpleEditButton({
|
|
|
|
Key? key,
|
2023-03-21 23:18:07 +00:00
|
|
|
this.editValue,
|
|
|
|
this.editLabel,
|
|
|
|
this.onValueChanged,
|
|
|
|
this.onPressedOverride,
|
|
|
|
}) : assert(
|
|
|
|
(editLabel != null && editValue != null && onValueChanged != null) ||
|
|
|
|
(editLabel == null &&
|
|
|
|
editValue == null &&
|
|
|
|
onValueChanged == null &&
|
|
|
|
onPressedOverride != null),
|
|
|
|
),
|
|
|
|
super(key: key);
|
2023-03-07 17:11:57 +00:00
|
|
|
|
2023-03-21 23:18:07 +00:00
|
|
|
final String? editValue;
|
|
|
|
final String? editLabel;
|
|
|
|
final void Function(String)? onValueChanged;
|
|
|
|
final VoidCallback? onPressedOverride;
|
2023-03-07 17:11:57 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-03-13 23:09:14 +00:00
|
|
|
if (Util.isDesktop) {
|
|
|
|
return SizedBox(
|
|
|
|
height: 26,
|
|
|
|
width: 26,
|
|
|
|
child: RawMaterialButton(
|
|
|
|
fillColor:
|
|
|
|
Theme.of(context).extension<StackColors>()!.buttonBackSecondary,
|
|
|
|
elevation: 0,
|
|
|
|
hoverElevation: 0,
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
2023-03-07 17:11:57 +00:00
|
|
|
),
|
2023-03-21 23:18:07 +00:00
|
|
|
onPressed: onPressedOverride ??
|
|
|
|
() async {
|
|
|
|
final result = await showDialog<String?>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
|
|
|
return DesktopDialog(
|
|
|
|
maxWidth: 580,
|
2023-04-03 16:19:18 +00:00
|
|
|
maxHeight: 300,
|
2023-03-21 23:18:07 +00:00
|
|
|
child: SingleFieldEditView(
|
|
|
|
initialValue: editValue!,
|
|
|
|
label: editLabel!,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2023-03-13 23:09:14 +00:00
|
|
|
);
|
2023-03-21 23:18:07 +00:00
|
|
|
if (result is String && result != editValue!) {
|
|
|
|
onValueChanged?.call(result);
|
|
|
|
}
|
2023-03-13 23:09:14 +00:00
|
|
|
},
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(5),
|
|
|
|
child: PencilIcon(
|
|
|
|
width: 16,
|
|
|
|
height: 16,
|
|
|
|
color: Theme.of(context).extension<StackColors>()!.textDark,
|
|
|
|
),
|
2023-03-07 17:11:57 +00:00
|
|
|
),
|
2023-03-13 23:09:14 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return GestureDetector(
|
2023-03-21 23:18:07 +00:00
|
|
|
onTap: onPressedOverride ??
|
|
|
|
() async {
|
|
|
|
final result = await Navigator.of(context).pushNamed(
|
|
|
|
SingleFieldEditView.routeName,
|
|
|
|
arguments: Tuple2(
|
|
|
|
editValue!,
|
|
|
|
editLabel!,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
if (result is String && result != editValue!) {
|
|
|
|
onValueChanged?.call(result);
|
|
|
|
}
|
|
|
|
},
|
2023-03-13 23:09:14 +00:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
SvgPicture.asset(
|
|
|
|
Assets.svg.pencil,
|
|
|
|
width: 10,
|
|
|
|
height: 10,
|
|
|
|
color: Theme.of(context).extension<StackColors>()!.infoItemIcons,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 4,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"Edit",
|
|
|
|
style: STextStyles.link2(context),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-03-07 17:11:57 +00:00
|
|
|
}
|
|
|
|
}
|