cake_wallet/lib/src/screens/seed/wallet_seed_page.dart

155 lines
6.2 KiB
Dart
Raw Normal View History

2020-01-04 19:31:52 +00:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
2020-07-06 20:09:03 +00:00
import 'package:provider/provider.dart';
import 'package:esys_flutter_share/esys_flutter_share.dart';
2020-01-04 19:31:52 +00:00
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/themes.dart';
import 'package:cake_wallet/theme_changer.dart';
2020-07-06 20:09:03 +00:00
import 'package:cake_wallet/view_model/wallet_seed_view_model.dart';
2020-01-04 19:31:52 +00:00
2020-07-06 20:09:03 +00:00
class WalletSeedPage extends BasePage {
WalletSeedPage(this.walletSeedViewModel, {this.onCloseCallback});
2020-01-08 12:26:34 +00:00
static final imageLight = Image.asset('assets/images/crypto_lock_light.png');
static final imageDark = Image.asset('assets/images/crypto_lock.png');
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
String get title => S.current.seed_title;
final VoidCallback onCloseCallback;
2020-07-06 20:09:03 +00:00
final WalletSeedViewModel walletSeedViewModel;
2020-01-04 19:31:52 +00:00
2020-01-08 12:26:34 +00:00
@override
2020-01-04 19:31:52 +00:00
void onClose(BuildContext context) =>
onCloseCallback != null ? onCloseCallback() : Navigator.of(context).pop();
@override
2020-07-06 20:09:03 +00:00
Widget leading(BuildContext context) =>
onCloseCallback != null ? Offstage() : super.leading(context);
2020-01-04 19:31:52 +00:00
@override
Widget trailing(BuildContext context) {
return onCloseCallback != null
? GestureDetector(
2020-07-06 20:09:03 +00:00
onTap: () => onClose(context),
child: Container(
width: 100,
height: 42,
alignment: Alignment.center,
margin: EdgeInsets.only(left: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(16)),
color: Theme.of(context).accentTextTheme.title.color),
child: Text(
S.of(context).seed_language_next,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Colors.blue),
),
),
2020-07-06 20:09:03 +00:00
)
: Offstage();
}
2020-01-04 19:31:52 +00:00
@override
Widget body(BuildContext context) {
final _themeChanger = Provider.of<ThemeChanger>(context);
2020-07-06 20:09:03 +00:00
final image =
_themeChanger.getTheme() == Themes.darkTheme ? imageDark : imageLight;
2020-01-04 19:31:52 +00:00
return Container(
2020-07-06 20:09:03 +00:00
padding: EdgeInsets.all(24),
child: Column(
children: <Widget>[
Flexible(
flex: 2,
child: AspectRatio(
aspectRatio: 1,
child: FittedBox(child: image, fit: BoxFit.fill))),
Flexible(
flex: 3,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 33),
child: Observer(builder: (_) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
2020-07-06 20:09:03 +00:00
walletSeedViewModel.name,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
2020-07-06 20:09:03 +00:00
color: Theme.of(context)
.primaryTextTheme
.title
.color),
),
Padding(
padding: EdgeInsets.only(top: 20),
child: Text(
2020-07-06 20:09:03 +00:00
walletSeedViewModel.seed,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14,
2020-07-06 20:09:03 +00:00
color: Theme.of(context)
.primaryTextTheme
.caption
.color),
),
)
],
);
2020-07-06 20:09:03 +00:00
}),
),
Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Flexible(
child: Container(
padding: EdgeInsets.only(right: 8.0),
child: PrimaryButton(
onPressed: () => Share.text(
S.of(context).seed_share,
2020-07-06 20:09:03 +00:00
walletSeedViewModel.seed,
'text/plain'),
text: S.of(context).save,
color: Colors.green,
textColor: Colors.white),
2020-07-06 20:09:03 +00:00
)),
Flexible(
child: Container(
padding: EdgeInsets.only(left: 8.0),
child: Builder(
builder: (context) => PrimaryButton(
onPressed: () {
2020-07-06 20:09:03 +00:00
Clipboard.setData(ClipboardData(
text: walletSeedViewModel.seed));
Scaffold.of(context).showSnackBar(
SnackBar(
2020-07-06 20:09:03 +00:00
content: Text(
S.of(context).copied_to_clipboard),
backgroundColor: Colors.green,
duration: Duration(milliseconds: 1500),
),
);
},
text: S.of(context).copy,
color: Theme.of(context).accentTextTheme.body2.color,
2020-07-06 20:09:03 +00:00
textColor: Colors.white)),
))
],
)
],
2020-07-06 20:09:03 +00:00
))
],
));
2020-01-04 19:31:52 +00:00
}
}