2021-03-03 18:54:23 +00:00
|
|
|
import 'package:cake_wallet/entities/wallet_type.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
|
|
import 'package:cake_wallet/routes.dart';
|
2021-04-26 18:06:21 +00:00
|
|
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
2020-12-16 20:45:45 +00:00
|
|
|
import 'package:cake_wallet/themes/theme_base.dart';
|
2021-04-26 18:06:21 +00:00
|
|
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
2020-07-23 12:20:52 +00:00
|
|
|
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
2020-05-29 15:10:11 +00:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/menu_widget.dart';
|
2020-07-21 17:22:41 +00:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/action_button.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/balance_page.dart';
|
2020-07-27 17:07:37 +00:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/address_page.dart';
|
2020-07-23 12:20:52 +00:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/transactions_page.dart';
|
2020-07-22 10:04:11 +00:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/widgets/sync_indicator.dart';
|
2020-07-27 17:07:37 +00:00
|
|
|
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart';
|
2021-03-03 18:54:23 +00:00
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
2021-05-11 13:52:48 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
2020-07-31 19:55:26 +00:00
|
|
|
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
2021-03-18 18:36:58 +00:00
|
|
|
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
class DashboardPage extends BasePage {
|
2020-07-27 17:07:37 +00:00
|
|
|
DashboardPage({
|
|
|
|
@required this.walletViewModel,
|
|
|
|
@required this.addressListViewModel,
|
|
|
|
});
|
2020-06-20 07:10:00 +00:00
|
|
|
|
2020-04-14 18:15:47 +00:00
|
|
|
@override
|
2021-05-11 13:52:48 +00:00
|
|
|
Color get backgroundLightColor =>
|
|
|
|
currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@override
|
2020-08-19 17:57:06 +00:00
|
|
|
Color get backgroundDarkColor => Colors.transparent;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget Function(BuildContext, Widget) get rootWrapper =>
|
2020-09-01 11:18:07 +00:00
|
|
|
(BuildContext context, Widget scaffold) => Container(
|
2020-08-19 17:57:06 +00:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
gradient: LinearGradient(colors: [
|
2020-09-01 11:18:07 +00:00
|
|
|
Theme.of(context).accentColor,
|
|
|
|
Theme.of(context).scaffoldBackgroundColor,
|
|
|
|
Theme.of(context).primaryColor,
|
|
|
|
], begin: Alignment.topRight, end: Alignment.bottomLeft)),
|
2020-08-19 17:57:06 +00:00
|
|
|
child: scaffold);
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-07-28 16:03:34 +00:00
|
|
|
@override
|
2021-04-26 18:06:21 +00:00
|
|
|
bool get resizeToAvoidBottomInset => false;
|
2020-07-28 16:03:34 +00:00
|
|
|
|
2020-07-31 15:29:21 +00:00
|
|
|
@override
|
2020-09-01 11:18:07 +00:00
|
|
|
Widget get endDrawer => MenuWidget(walletViewModel);
|
2020-07-31 15:29:21 +00:00
|
|
|
|
2020-07-22 10:04:11 +00:00
|
|
|
@override
|
|
|
|
Widget middle(BuildContext context) {
|
|
|
|
return SyncIndicator(dashboardViewModel: walletViewModel);
|
|
|
|
}
|
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
@override
|
2020-07-06 20:09:03 +00:00
|
|
|
Widget trailing(BuildContext context) {
|
2021-05-11 13:52:48 +00:00
|
|
|
final menuButton = Image.asset('assets/images/menu.png',
|
|
|
|
color: Theme.of(context).accentTextTheme.display3.backgroundColor);
|
2020-07-06 20:09:03 +00:00
|
|
|
|
|
|
|
return Container(
|
2020-09-01 11:18:07 +00:00
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
width: 40,
|
|
|
|
child: FlatButton(
|
|
|
|
highlightColor: Colors.transparent,
|
|
|
|
splashColor: Colors.transparent,
|
|
|
|
padding: EdgeInsets.all(0),
|
|
|
|
onPressed: () => onOpenEndDrawer(),
|
|
|
|
child: menuButton));
|
2020-07-06 20:09:03 +00:00
|
|
|
}
|
2020-04-14 18:15:47 +00:00
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
final DashboardViewModel walletViewModel;
|
2020-07-27 17:07:37 +00:00
|
|
|
final WalletAddressListViewModel addressListViewModel;
|
|
|
|
final controller = PageController(initialPage: 1);
|
2020-07-21 17:22:41 +00:00
|
|
|
|
|
|
|
var pages = <Widget>[];
|
|
|
|
bool _isEffectsInstalled = false;
|
2020-07-06 20:09:03 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget body(BuildContext context) {
|
2020-12-11 18:46:20 +00:00
|
|
|
final sendImage = Image.asset('assets/images/upload.png',
|
2021-05-11 13:52:48 +00:00
|
|
|
height: 22.24,
|
|
|
|
width: 24,
|
2020-12-11 18:46:20 +00:00
|
|
|
color: Theme.of(context).accentTextTheme.display3.backgroundColor);
|
|
|
|
final exchangeImage = Image.asset('assets/images/transfer.png',
|
2021-05-11 13:52:48 +00:00
|
|
|
height: 24.27,
|
|
|
|
width: 22.25,
|
2020-12-11 18:46:20 +00:00
|
|
|
color: Theme.of(context).accentTextTheme.display3.backgroundColor);
|
2021-03-03 18:54:23 +00:00
|
|
|
final buyImage = Image.asset('assets/images/coins.png',
|
2021-05-11 13:52:48 +00:00
|
|
|
height: 22.24,
|
|
|
|
width: 24,
|
2020-12-11 18:46:20 +00:00
|
|
|
color: Theme.of(context).accentTextTheme.display3.backgroundColor);
|
2021-05-11 13:52:48 +00:00
|
|
|
_setEffects(context);
|
2020-07-21 17:22:41 +00:00
|
|
|
|
|
|
|
return SafeArea(
|
2020-09-01 11:18:07 +00:00
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
2020-07-22 10:04:11 +00:00
|
|
|
child: PageView.builder(
|
2020-09-01 11:18:07 +00:00
|
|
|
controller: controller,
|
|
|
|
itemCount: pages.length,
|
2020-09-09 14:13:44 +00:00
|
|
|
itemBuilder: (context, index) => pages[index])),
|
2020-09-01 11:18:07 +00:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(bottom: 24),
|
2020-07-31 19:55:26 +00:00
|
|
|
child: SmoothPageIndicator(
|
2020-07-22 10:04:11 +00:00
|
|
|
controller: controller,
|
2020-09-01 11:18:07 +00:00
|
|
|
count: pages.length,
|
2020-07-31 19:55:26 +00:00
|
|
|
effect: ColorTransitionEffect(
|
2020-09-01 11:18:07 +00:00
|
|
|
spacing: 6.0,
|
|
|
|
radius: 6.0,
|
|
|
|
dotWidth: 6.0,
|
|
|
|
dotHeight: 6.0,
|
|
|
|
dotColor: Theme.of(context).indicatorColor,
|
2021-05-11 13:52:48 +00:00
|
|
|
activeDotColor: Theme.of(context)
|
|
|
|
.accentTextTheme
|
|
|
|
.display1
|
2020-12-11 18:46:20 +00:00
|
|
|
.backgroundColor),
|
2020-09-01 11:18:07 +00:00
|
|
|
)),
|
|
|
|
Container(
|
2020-09-25 11:25:08 +00:00
|
|
|
padding: EdgeInsets.only(left: 45, right: 45, bottom: 24),
|
2021-04-26 18:06:21 +00:00
|
|
|
child: Row(
|
2020-09-28 15:47:43 +00:00
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
2020-09-01 11:18:07 +00:00
|
|
|
children: <Widget>[
|
2020-09-25 11:25:08 +00:00
|
|
|
ActionButton(
|
2020-09-26 12:19:33 +00:00
|
|
|
image: sendImage,
|
|
|
|
title: S.of(context).send,
|
|
|
|
route: Routes.send),
|
2020-09-25 11:25:08 +00:00
|
|
|
ActionButton(
|
2020-09-26 12:19:33 +00:00
|
|
|
image: exchangeImage,
|
|
|
|
title: S.of(context).exchange,
|
|
|
|
route: Routes.exchange),
|
2021-05-28 09:06:50 +00:00
|
|
|
ActionButton(
|
|
|
|
image: buyImage,
|
|
|
|
title: S.of(context).buy,
|
|
|
|
onClick: () async =>
|
|
|
|
await _onClickBuyButton(context),
|
2021-04-12 18:22:22 +00:00
|
|
|
),
|
2020-09-01 11:18:07 +00:00
|
|
|
],
|
2021-04-26 18:06:21 +00:00
|
|
|
),
|
2020-09-01 11:18:07 +00:00
|
|
|
)
|
|
|
|
],
|
|
|
|
));
|
2020-07-06 20:09:03 +00:00
|
|
|
}
|
|
|
|
|
2021-05-11 13:52:48 +00:00
|
|
|
void _setEffects(BuildContext context) {
|
2020-07-21 17:22:41 +00:00
|
|
|
if (_isEffectsInstalled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-04 10:30:59 +00:00
|
|
|
pages.add(AddressPage(addressListViewModel: addressListViewModel,
|
|
|
|
walletViewModel: walletViewModel));
|
2020-07-21 17:22:41 +00:00
|
|
|
pages.add(BalancePage(dashboardViewModel: walletViewModel));
|
2020-07-23 12:20:52 +00:00
|
|
|
pages.add(TransactionsPage(dashboardViewModel: walletViewModel));
|
2020-07-21 17:22:41 +00:00
|
|
|
|
2021-05-11 13:52:48 +00:00
|
|
|
autorun((_) async {
|
|
|
|
if (!walletViewModel.isOutdatedElectrumWallet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await Future<void>.delayed(Duration(seconds: 1));
|
|
|
|
await showPopUp<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: S.of(context).pre_seed_title,
|
|
|
|
alertContent:
|
2021-06-07 18:44:58 +00:00
|
|
|
S.of(context).outdated_electrum_wallet_description,
|
2021-05-11 13:52:48 +00:00
|
|
|
buttonText: S.of(context).understand,
|
|
|
|
buttonAction: () => Navigator.of(context).pop());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-21 17:22:41 +00:00
|
|
|
_isEffectsInstalled = true;
|
|
|
|
}
|
2021-04-26 18:06:21 +00:00
|
|
|
|
2021-05-11 13:52:48 +00:00
|
|
|
Future<void> _onClickBuyButton(BuildContext context) async {
|
2021-04-26 18:06:21 +00:00
|
|
|
final walletType = walletViewModel.type;
|
|
|
|
|
|
|
|
switch (walletType) {
|
2021-06-08 20:06:22 +00:00
|
|
|
case WalletType.monero:
|
2021-04-26 18:06:21 +00:00
|
|
|
await showPopUp<void>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertWithOneAction(
|
|
|
|
alertTitle: S.of(context).buy,
|
|
|
|
alertContent: S.of(context).buy_alert_content,
|
|
|
|
buttonText: S.of(context).ok,
|
|
|
|
buttonAction: () => Navigator.of(context).pop());
|
|
|
|
});
|
|
|
|
break;
|
2021-06-08 20:06:22 +00:00
|
|
|
default:
|
|
|
|
Navigator.of(context).pushNamed(Routes.preOrder);
|
|
|
|
break;
|
2021-04-26 18:06:21 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|