stack_wallet/lib/pages/exchange_view/edit_trade_note_view.dart

148 lines
5.4 KiB
Dart
Raw Normal View History

2022-08-26 08:11:35 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/providers/exchange/trade_note_service_provider.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_theme.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/icon_widgets/x_icon.dart';
import 'package:stackwallet/widgets/stack_text_field.dart';
import 'package:stackwallet/widgets/textfield_icon_button.dart';
class EditTradeNoteView extends ConsumerStatefulWidget {
const EditTradeNoteView({
Key? key,
required this.tradeId,
required this.note,
}) : super(key: key);
static const String routeName = "/editTradeNote";
final String tradeId;
final String note;
@override
ConsumerState<EditTradeNoteView> createState() => _EditNoteViewState();
}
class _EditNoteViewState extends ConsumerState<EditTradeNoteView> {
late final TextEditingController _noteController;
final noteFieldFocusNode = FocusNode();
@override
void initState() {
_noteController = TextEditingController();
_noteController.text = widget.note;
super.initState();
}
@override
void dispose() {
_noteController.dispose();
noteFieldFocusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
2022-09-21 00:46:07 +00:00
backgroundColor: StackTheme.instance.color.background,
2022-08-26 08:11:35 +00:00
appBar: AppBar(
2022-09-21 00:46:07 +00:00
backgroundColor: StackTheme.instance.color.background,
2022-08-26 08:11:35 +00:00
leading: AppBarBackButton(
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();
}
},
),
title: Text(
"Edit trade note",
style: STextStyles.navBarTitle,
),
),
body: Padding(
padding: const EdgeInsets.all(12),
child: LayoutBuilder(
builder: (context, constraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraints.maxHeight,
),
child: IntrinsicHeight(
child: Padding(
padding: const EdgeInsets.all(4),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
child: TextField(
controller: _noteController,
style: STextStyles.field,
focusNode: noteFieldFocusNode,
onChanged: (_) => setState(() {}),
decoration: standardInputDecoration(
"Note",
noteFieldFocusNode,
).copyWith(
suffixIcon: _noteController.text.isNotEmpty
? Padding(
padding: const EdgeInsets.only(right: 0),
child: UnconstrainedBox(
child: Row(
children: [
TextFieldIconButton(
child: const XIcon(),
onTap: () async {
setState(() {
_noteController.text = "";
});
},
),
],
),
),
)
: null,
),
),
),
const Spacer(),
TextButton(
onPressed: () async {
await ref.read(tradeNoteServiceProvider).set(
tradeId: widget.tradeId,
note: _noteController.text,
);
if (mounted) {
Navigator.of(context).pop();
}
},
style: StackTheme.instance
.getPrimaryEnabledButtonColor(context),
2022-08-26 08:11:35 +00:00
child: Text(
"Save",
style: STextStyles.button,
),
)
],
),
),
),
),
);
},
),
),
);
}
}