2020-04-21 18:23:40 +00:00
|
|
|
import 'dart:ui';
|
2020-08-27 16:54:34 +00:00
|
|
|
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
|
2020-04-21 18:23:40 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
import 'package:cake_wallet/src/domain/common/wallet_type.dart';
|
2020-04-21 18:23:40 +00:00
|
|
|
import 'package:cake_wallet/src/screens/dashboard/wallet_menu.dart';
|
|
|
|
|
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> {
|
|
|
|
final moneroIcon = Image.asset('assets/images/monero.png');
|
2020-07-06 20:09:03 +00:00
|
|
|
final bitcoinIcon = Image.asset('assets/images/bitcoin.png');
|
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
|
|
|
double opacity;
|
|
|
|
|
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-04-21 18:23:40 +00:00
|
|
|
opacity = 0;
|
2020-04-22 16:40:16 +00:00
|
|
|
|
|
|
|
headerHeight = 120;
|
|
|
|
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;
|
|
|
|
opacity = 1;
|
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-08-27 16:54:34 +00:00
|
|
|
final walletMenu =
|
|
|
|
WalletMenu(context, () async => widget.dashboardViewModel.reconnect());
|
2020-04-21 18:23:40 +00:00
|
|
|
final itemCount = walletMenu.items.length;
|
|
|
|
|
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)),
|
|
|
|
color: Theme.of(context).hintColor),
|
|
|
|
)),
|
2020-06-05 09:34:15 +00:00
|
|
|
SizedBox(width: 12),
|
|
|
|
Expanded(
|
|
|
|
child: GestureDetector(
|
2020-07-06 20:09:03 +00:00
|
|
|
onTap: () => null,
|
2020-04-21 18:23:40 +00:00
|
|
|
child: Container(
|
2020-07-06 20:09:03 +00:00
|
|
|
width: menuWidth,
|
|
|
|
height: double.infinity,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(24),
|
|
|
|
bottomLeft: Radius.circular(24)),
|
|
|
|
color: Theme.of(context).primaryTextTheme.display1.color),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(24),
|
|
|
|
bottomLeft: Radius.circular(24)),
|
|
|
|
child: ListView.separated(
|
|
|
|
itemBuilder: (_, index) {
|
|
|
|
if (index == 0) {
|
|
|
|
return Container(
|
|
|
|
height: headerHeight,
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: 24,
|
|
|
|
top: fromTopEdge,
|
|
|
|
right: 24,
|
|
|
|
bottom: fromBottomEdge),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.only(topLeft: Radius.circular(24)),
|
|
|
|
color: Theme.of(context)
|
|
|
|
.primaryTextTheme
|
|
|
|
.display2
|
|
|
|
.color),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
2020-08-27 16:54:34 +00:00
|
|
|
_iconFor(type: widget.dashboardViewModel.type),
|
2020-07-06 20:09:03 +00:00
|
|
|
SizedBox(width: 16),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
height: 40,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2020-08-27 16:54:34 +00:00
|
|
|
mainAxisAlignment:
|
|
|
|
widget.dashboardViewModel.subname != null
|
|
|
|
? MainAxisAlignment.spaceBetween
|
|
|
|
: MainAxisAlignment.center,
|
2020-07-06 20:09:03 +00:00
|
|
|
children: <Widget>[
|
|
|
|
Text(
|
2020-08-27 16:54:34 +00:00
|
|
|
widget.dashboardViewModel.name,
|
2020-07-06 20:09:03 +00:00
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.primaryTextTheme
|
|
|
|
.title
|
|
|
|
.color,
|
|
|
|
decoration: TextDecoration.none,
|
|
|
|
fontFamily: 'Avenir Next',
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
),
|
2020-08-27 16:54:34 +00:00
|
|
|
if (widget.dashboardViewModel.subname != null)
|
2020-07-06 20:09:03 +00:00
|
|
|
Text(
|
2020-08-27 16:54:34 +00:00
|
|
|
widget.dashboardViewModel.subname,
|
2020-06-05 09:34:15 +00:00
|
|
|
style: TextStyle(
|
2020-07-06 20:09:03 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.primaryTextTheme
|
|
|
|
.caption
|
|
|
|
.color,
|
2020-06-05 09:34:15 +00:00
|
|
|
decoration: TextDecoration.none,
|
2020-07-06 20:09:03 +00:00
|
|
|
fontFamily: 'Avenir Next',
|
|
|
|
fontSize: 12),
|
2020-06-05 09:34:15 +00:00
|
|
|
)
|
2020-07-06 20:09:03 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2020-04-22 16:40:16 +00:00
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
index -= 1;
|
|
|
|
final item = walletMenu.items[index];
|
|
|
|
final image = walletMenu.images[index] ?? Offstage();
|
2020-04-22 16:40:16 +00:00
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
walletMenu.action(index);
|
|
|
|
},
|
|
|
|
child: index == itemCount - 1
|
|
|
|
? Container(
|
|
|
|
height: headerHeight,
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: 24,
|
|
|
|
right: 24,
|
|
|
|
top: fromBottomEdge,
|
|
|
|
bottom: fromTopEdge),
|
|
|
|
alignment: Alignment.topLeft,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
bottomLeft: Radius.circular(24)),
|
|
|
|
color: Theme.of(context)
|
|
|
|
.primaryTextTheme
|
|
|
|
.display1
|
|
|
|
.color,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
image,
|
|
|
|
SizedBox(width: 16),
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
item,
|
|
|
|
style: TextStyle(
|
|
|
|
decoration: TextDecoration.none,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.primaryTextTheme
|
|
|
|
.title
|
|
|
|
.color,
|
|
|
|
fontFamily: 'Avenir Next',
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
2020-06-05 09:34:15 +00:00
|
|
|
: Container(
|
2020-07-06 20:09:03 +00:00
|
|
|
height: tileHeight,
|
|
|
|
padding: EdgeInsets.only(left: 24, right: 24),
|
|
|
|
color: Theme.of(context)
|
|
|
|
.primaryTextTheme
|
|
|
|
.display1
|
|
|
|
.color,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
image,
|
|
|
|
SizedBox(width: 16),
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
item,
|
|
|
|
style: TextStyle(
|
|
|
|
decoration: TextDecoration.none,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.primaryTextTheme
|
|
|
|
.title
|
|
|
|
.color,
|
|
|
|
fontFamily: 'Avenir Next',
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: FontWeight.bold),
|
|
|
|
))
|
|
|
|
],
|
|
|
|
),
|
2020-06-05 09:34:15 +00:00
|
|
|
),
|
2020-07-06 20:09:03 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
separatorBuilder: (_, index) => Container(
|
|
|
|
height: 1,
|
|
|
|
color: Theme.of(context).dividerColor,
|
2020-04-22 16:40:16 +00:00
|
|
|
),
|
2020-07-06 20:09:03 +00:00
|
|
|
itemCount: itemCount + 1),
|
|
|
|
),
|
2020-04-21 18:23:40 +00:00
|
|
|
),
|
2020-07-06 20:09:03 +00:00
|
|
|
))
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|