CakeWallet/lib/src/screens/receive/receive_page.dart

246 lines
9.5 KiB
Dart
Raw Normal View History

import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
2022-12-23 23:58:39 +02:00
import 'package:cake_wallet/src/widgets/section_divider.dart';
import 'package:cake_wallet/themes/theme_base.dart';
import 'package:cake_wallet/utils/share_util.dart';
2020-09-25 18:32:44 +03:00
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cw_core/wallet_type.dart';
2020-01-04 21:31:52 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/generated/i18n.dart';
2020-07-06 23:09:03 +03:00
import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/src/screens/monero_accounts/monero_account_list_page.dart';
import 'package:cake_wallet/src/screens/receive/widgets/header_tile.dart';
2020-06-20 10:10:00 +03:00
import 'package:cake_wallet/src/screens/receive/widgets/address_cell.dart';
2020-07-06 23:09:03 +03:00
import 'package:cake_wallet/view_model/wallet_address_list/wallet_account_list_header.dart';
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_header.dart';
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_item.dart';
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart';
import 'package:cake_wallet/src/screens/receive/widgets/qr_widget.dart';
2020-11-16 20:17:03 +02:00
import 'package:keyboard_actions/keyboard_actions.dart';
2020-01-04 21:31:52 +02:00
2020-06-20 10:10:00 +03:00
class ReceivePage extends BasePage {
2022-10-12 13:09:57 -04:00
ReceivePage({required this.addressListViewModel}) : _cryptoAmountFocus = FocusNode();
2020-01-04 21:31:52 +02:00
2020-07-06 23:09:03 +03:00
final WalletAddressListViewModel addressListViewModel;
2020-01-04 21:31:52 +02:00
@override
String get title => S.current.receive;
2020-01-04 21:31:52 +02:00
2020-06-20 10:10:00 +03:00
@override
Color get backgroundLightColor => currentTheme.type == ThemeType.bright
? Colors.transparent : Colors.white;
2020-06-20 10:10:00 +03:00
@override
Color get backgroundDarkColor => Colors.transparent;
@override
bool get resizeToAvoidBottomInset => false;
final FocusNode _cryptoAmountFocus;
@override
Widget leading(BuildContext context) {
final _backButton = Icon(Icons.arrow_back_ios,
2022-10-12 13:09:57 -04:00
color: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!,
size: 16,);
return SizedBox(
height: 37,
width: 37,
child: ButtonTheme(
minWidth: double.minPositive,
2022-10-12 13:09:57 -04:00
child: TextButton(
// FIX-ME: Style
//highlightColor: Colors.transparent,
//splashColor: Colors.transparent,
//padding: EdgeInsets.all(0),
onPressed: () => onClose(context),
child: _backButton),
),
);
}
@override
Widget middle(BuildContext context) {
return Text(
title,
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
fontFamily: 'Lato',
2022-10-12 13:09:57 -04:00
color: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!),
);
}
2020-11-16 20:17:03 +02:00
@override
Widget Function(BuildContext, Widget) get rootWrapper =>
2020-09-25 18:32:44 +03:00
(BuildContext context, Widget scaffold) => Container(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
2020-09-25 18:32:44 +03:00
Theme.of(context).accentColor,
Theme.of(context).scaffoldBackgroundColor,
Theme.of(context).primaryColor,
], begin: Alignment.topRight, end: Alignment.bottomLeft)),
child: scaffold);
2020-01-04 21:31:52 +02:00
2020-06-20 10:10:00 +03:00
@override
Widget trailing(BuildContext context) {
2020-09-25 18:32:44 +03:00
final shareImage =
Image.asset('assets/images/share.png',
2022-10-12 13:09:57 -04:00
color: Theme.of(context).accentTextTheme!.headline2!.backgroundColor!);
return Material(
color: Colors.transparent,
child: IconButton(
padding: EdgeInsets.zero,
constraints: BoxConstraints(),
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
iconSize: 25,
onPressed: () {
ShareUtil.share(
text: addressListViewModel.address.address,
context: context,
);
},
icon: shareImage
)
2020-06-20 10:10:00 +03:00
);
}
2020-06-20 10:10:00 +03:00
@override
Widget body(BuildContext context) {
2022-03-30 17:57:04 +02:00
return (addressListViewModel.type == WalletType.monero || addressListViewModel.type == WalletType.haven)
? KeyboardActions(
2020-11-16 20:17:03 +02:00
config: KeyboardActionsConfig(
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
2022-10-12 13:09:57 -04:00
keyboardBarColor: Theme.of(context).accentTextTheme!.bodyText1!
.backgroundColor!,
2020-11-16 20:17:03 +02:00
nextFocus: false,
actions: [
KeyboardActionsItem(
focusNode: _cryptoAmountFocus,
toolbarButtons: [(_) => KeyboardDoneButton()],
)
]),
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(24, 80, 24, 24),
2020-11-16 20:17:03 +02:00
child: QRWidget(
addressListViewModel: addressListViewModel,
isAmountFieldShow: true,
amountTextFieldFocusNode: _cryptoAmountFocus,
isLight: currentTheme.type == ThemeType.light),
2020-11-16 20:17:03 +02:00
),
Observer(
builder: (_) => ListView.separated(
padding: EdgeInsets.all(0),
2022-12-28 14:00:59 +02:00
separatorBuilder: (context, _) => const SectionDivider(),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: addressListViewModel.items.length,
itemBuilder: (context, index) {
final item = addressListViewModel.items[index];
Widget cell = Container();
if (item is WalletAccountListHeader) {
cell = HeaderTile(
onTap: () async => await showPopUp<void>(
context: context,
builder: (_) =>
getIt.get<MoneroAccountListPage>()),
title: S.of(context).accounts,
icon: Icon(
Icons.arrow_forward_ios,
size: 14,
color:
2022-10-12 13:09:57 -04:00
Theme.of(context).textTheme!.headline4!.color!,
));
}
if (item is WalletAddressListHeader) {
cell = HeaderTile(
onTap: () => Navigator.of(context)
.pushNamed(Routes.newSubaddress),
title: S.of(context).addresses,
icon: Icon(
Icons.add,
size: 20,
color:
2022-10-12 13:09:57 -04:00
Theme.of(context).textTheme!.headline4!.color!,
));
}
if (item is WalletAddressListItem) {
cell = Observer(builder: (_) {
final isCurrent = item.address ==
addressListViewModel.address.address;
final backgroundColor = isCurrent
? Theme.of(context)
2022-10-12 13:09:57 -04:00
.textTheme!
.headline2!
.decorationColor!
: Theme.of(context)
2022-10-12 13:09:57 -04:00
.textTheme!
.headline3!
.decorationColor!;
final textColor = isCurrent
2022-10-12 13:09:57 -04:00
? Theme.of(context).textTheme!.headline2!.color!
: Theme.of(context).textTheme!.headline3!.color!;
return AddressCell.fromItem(item,
isCurrent: isCurrent,
backgroundColor: backgroundColor,
textColor: textColor,
onTap: (_) => addressListViewModel.setAddress(item),
onEdit: () => Navigator.of(context).pushNamed(
Routes.newSubaddress,
arguments: item));
});
}
return index != 0
? cell
: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30)),
child: cell,
);
})),
2020-11-16 20:17:03 +02:00
],
),
)) : Padding(
padding: EdgeInsets.fromLTRB(24, 24, 24, 32),
child: Column(
children: [
Expanded(
flex: 7,
child: QRWidget(
addressListViewModel: addressListViewModel,
isAmountFieldShow: true,
amountTextFieldFocusNode: _cryptoAmountFocus,
isLight: currentTheme.type == ThemeType.light),
),
Expanded(
flex: 2,
child: SizedBox(),
),
Text(S.of(context).electrum_address_disclaimer,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 15,
color: Theme.of(context)
2022-10-12 13:09:57 -04:00
.accentTextTheme!
.headline3!
.backgroundColor!)),
],
),
);
2020-01-04 21:31:52 +02:00
}
2020-06-20 10:10:00 +03:00
}