2020-04-21 18:23:40 +00:00
|
|
|
import 'dart:ui';
|
|
|
|
import 'package:flutter/material.dart';
|
2020-09-01 11:18:07 +00:00
|
|
|
import 'package:cake_wallet/palette.dart';
|
|
|
|
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/entities/wallet_type.dart';
|
2020-04-21 18:23:40 +00:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/wallet_menu.dart';
|
2020-08-20 17:43:54 +00:00
|
|
|
import 'package:flutter/rendering.dart';
|
2020-11-17 18:16:58 +00:00
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
2020-04-21 18:23:40 +00:00
|
|
|
|
2020-08-27 16:54:34 +00:00
|
|
|
// FIXME: terrible design.
|
|
|
|
|
2020-04-21 18:23:40 +00:00
|
|
|
class MenuWidget extends StatefulWidget {
|
2020-08-27 16:54:34 +00:00
|
|
|
MenuWidget(this.dashboardViewModel);
|
2020-07-06 20:09:03 +00:00
|
|
|
|
2020-08-27 16:54:34 +00:00
|
|
|
final DashboardViewModel dashboardViewModel;
|
2020-07-06 20:09:03 +00:00
|
|
|
|
2020-04-21 18:23:40 +00:00
|
|
|
@override
|
|
|
|
MenuWidgetState createState() => MenuWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class MenuWidgetState extends State<MenuWidget> {
|
2020-08-28 20:04:48 +00:00
|
|
|
Image moneroIcon;
|
|
|
|
Image bitcoinIcon;
|
2020-04-22 16:40:16 +00:00
|
|
|
final largeScreen = 731;
|
|
|
|
|
2020-04-21 18:23:40 +00:00
|
|
|
double menuWidth;
|
|
|
|
double screenWidth;
|
2020-04-22 16:40:16 +00:00
|
|
|
double screenHeight;
|
2020-04-21 18:23:40 +00:00
|
|
|
|
2020-04-22 16:40:16 +00:00
|
|
|
double headerHeight;
|
|
|
|
double tileHeight;
|
|
|
|
double fromTopEdge;
|
|
|
|
double fromBottomEdge;
|
|
|
|
|
2020-04-21 18:23:40 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
menuWidth = 0;
|
|
|
|
screenWidth = 0;
|
2020-04-22 16:40:16 +00:00
|
|
|
screenHeight = 0;
|
|
|
|
|
2020-08-28 20:04:48 +00:00
|
|
|
headerHeight = 137;
|
2020-04-22 16:40:16 +00:00
|
|
|
tileHeight = 75;
|
|
|
|
fromTopEdge = 50;
|
|
|
|
fromBottomEdge = 30;
|
|
|
|
|
2020-04-21 18:23:40 +00:00
|
|
|
super.initState();
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback(afterLayout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void afterLayout(dynamic _) {
|
|
|
|
screenWidth = MediaQuery.of(context).size.width;
|
2020-04-22 16:40:16 +00:00
|
|
|
screenHeight = MediaQuery.of(context).size.height;
|
|
|
|
|
2020-04-21 18:23:40 +00:00
|
|
|
setState(() {
|
|
|
|
menuWidth = screenWidth;
|
2020-04-22 16:40:16 +00:00
|
|
|
|
|
|
|
if (screenHeight > largeScreen) {
|
|
|
|
final scale = screenHeight / largeScreen;
|
|
|
|
tileHeight *= scale;
|
|
|
|
headerHeight *= scale;
|
|
|
|
fromTopEdge *= scale;
|
|
|
|
fromBottomEdge *= scale;
|
|
|
|
}
|
2020-04-21 18:23:40 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-12-16 19:16:47 +00:00
|
|
|
final walletMenu = WalletMenu(
|
|
|
|
context,
|
|
|
|
() async => widget.dashboardViewModel.reconnect(),
|
|
|
|
widget.dashboardViewModel.hasRescan);
|
2020-04-21 18:23:40 +00:00
|
|
|
final itemCount = walletMenu.items.length;
|
|
|
|
|
2020-08-28 20:04:48 +00:00
|
|
|
moneroIcon = Image.asset('assets/images/monero_menu.png',
|
2020-09-01 11:18:07 +00:00
|
|
|
color: Theme.of(context).accentTextTheme.overline.decorationColor);
|
2020-08-28 20:04:48 +00:00
|
|
|
bitcoinIcon = Image.asset('assets/images/bitcoin_menu.png',
|
2020-09-01 11:18:07 +00:00
|
|
|
color: Theme.of(context).accentTextTheme.overline.decorationColor);
|
2020-08-28 20:04:48 +00:00
|
|
|
|
2020-06-05 09:34:15 +00:00
|
|
|
return Row(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
2020-07-06 20:09:03 +00:00
|
|
|
padding: EdgeInsets.only(left: 24),
|
|
|
|
child: Container(
|
|
|
|
height: 60,
|
|
|
|
width: 4,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(2)),
|
2020-08-20 17:43:54 +00:00
|
|
|
color: PaletteDark.gray),
|
2020-07-06 20:09:03 +00:00
|
|
|
)),
|
2020-06-05 09:34:15 +00:00
|
|
|
SizedBox(width: 12),
|
|
|
|
Expanded(
|
2020-08-20 17:43:54 +00:00
|
|
|
child: ClipRRect(
|
2020-07-06 20:09:03 +00:00
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(24),
|
|
|
|
bottomLeft: Radius.circular(24)),
|
2020-09-01 11:18:07 +00:00
|
|
|
child: Container(
|
|
|
|
color: Theme.of(context).textTheme.body2.decorationColor,
|
|
|
|
child: ListView.separated(
|
|
|
|
padding: EdgeInsets.only(top: 0),
|
|
|
|
itemBuilder: (_, index) {
|
|
|
|
if (index == 0) {
|
|
|
|
return Container(
|
|
|
|
height: headerHeight,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
gradient: LinearGradient(
|
|
|
|
colors: [
|
|
|
|
Theme.of(context)
|
|
|
|
.accentTextTheme
|
|
|
|
.display1
|
|
|
|
.color,
|
|
|
|
Theme.of(context)
|
|
|
|
.accentTextTheme
|
|
|
|
.display1
|
|
|
|
.decorationColor,
|
|
|
|
],
|
|
|
|
begin: Alignment.topLeft,
|
|
|
|
end: Alignment.bottomRight),
|
|
|
|
),
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: 24,
|
|
|
|
top: fromTopEdge,
|
|
|
|
right: 24,
|
|
|
|
bottom: fromBottomEdge),
|
2020-08-20 17:43:54 +00:00
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
2020-09-01 11:18:07 +00:00
|
|
|
_iconFor(type: widget.dashboardViewModel.type),
|
|
|
|
SizedBox(width: 12),
|
2020-08-20 17:43:54 +00:00
|
|
|
Expanded(
|
2020-09-01 11:18:07 +00:00
|
|
|
child: Container(
|
|
|
|
height: 42,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment:
|
|
|
|
CrossAxisAlignment.start,
|
|
|
|
mainAxisAlignment:
|
|
|
|
widget.dashboardViewModel.subname !=
|
|
|
|
null
|
|
|
|
? MainAxisAlignment.spaceBetween
|
|
|
|
: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Text(
|
|
|
|
widget.dashboardViewModel.name,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
if (widget.dashboardViewModel.subname !=
|
|
|
|
null)
|
2020-12-16 19:16:47 +00:00
|
|
|
Observer(
|
|
|
|
builder: (_) => Text(
|
|
|
|
widget.dashboardViewModel
|
|
|
|
.subname,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.accentTextTheme
|
|
|
|
.overline
|
|
|
|
.decorationColor,
|
|
|
|
fontWeight:
|
|
|
|
FontWeight.w500,
|
|
|
|
fontSize: 12),
|
|
|
|
))
|
2020-09-01 11:18:07 +00:00
|
|
|
],
|
2020-07-06 20:09:03 +00:00
|
|
|
),
|
2020-09-01 11:18:07 +00:00
|
|
|
))
|
2020-08-20 17:43:54 +00:00
|
|
|
],
|
2020-06-05 09:34:15 +00:00
|
|
|
),
|
2020-09-01 11:18:07 +00:00
|
|
|
);
|
|
|
|
}
|
2020-04-22 16:40:16 +00:00
|
|
|
|
2020-09-01 11:18:07 +00:00
|
|
|
index--;
|
2020-04-22 16:40:16 +00:00
|
|
|
|
2020-09-01 11:18:07 +00:00
|
|
|
final item = walletMenu.items[index];
|
2020-10-22 16:50:53 +00:00
|
|
|
final title = item.title;
|
|
|
|
final image = item.image ?? Offstage();
|
2020-09-01 11:18:07 +00:00
|
|
|
final isLastTile = index == itemCount - 1;
|
|
|
|
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
walletMenu.action(index);
|
|
|
|
},
|
|
|
|
child: Container(
|
2020-07-06 20:09:03 +00:00
|
|
|
color: Theme.of(context)
|
2020-09-01 11:18:07 +00:00
|
|
|
.textTheme
|
|
|
|
.body2
|
|
|
|
.decorationColor,
|
|
|
|
height: isLastTile ? headerHeight : tileHeight,
|
|
|
|
padding: isLastTile
|
|
|
|
? EdgeInsets.only(
|
|
|
|
left: 24,
|
|
|
|
right: 24,
|
|
|
|
top: fromBottomEdge,
|
|
|
|
//bottom: fromTopEdge
|
|
|
|
)
|
|
|
|
: EdgeInsets.only(left: 24, right: 24),
|
|
|
|
alignment: isLastTile ? Alignment.topLeft : null,
|
2020-07-06 20:09:03 +00:00
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
image,
|
|
|
|
SizedBox(width: 16),
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
2020-10-22 16:50:53 +00:00
|
|
|
title,
|
2020-07-06 20:09:03 +00:00
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context)
|
2020-09-01 11:18:07 +00:00
|
|
|
.textTheme
|
|
|
|
.display2
|
2020-07-06 20:09:03 +00:00
|
|
|
.color,
|
2020-09-01 11:18:07 +00:00
|
|
|
fontSize: 16,
|
2020-07-06 20:09:03 +00:00
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
))
|
|
|
|
],
|
|
|
|
),
|
2020-09-01 11:18:07 +00:00
|
|
|
));
|
|
|
|
},
|
|
|
|
separatorBuilder: (_, index) => Container(
|
|
|
|
height: 1,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.primaryTextTheme
|
|
|
|
.caption
|
|
|
|
.decorationColor,
|
|
|
|
),
|
|
|
|
itemCount: itemCount + 1),
|
|
|
|
)))
|
2020-06-05 09:34:15 +00:00
|
|
|
],
|
2020-04-21 18:23:40 +00:00
|
|
|
);
|
|
|
|
}
|
2020-07-06 20:09:03 +00:00
|
|
|
|
|
|
|
Image _iconFor({@required WalletType type}) {
|
|
|
|
switch (type) {
|
|
|
|
case WalletType.monero:
|
|
|
|
return moneroIcon;
|
|
|
|
case WalletType.bitcoin:
|
|
|
|
return bitcoinIcon;
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|