mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-02-02 03:06:35 +00:00
Merge pull request #774 from cake-tech/CW-310-add-constraints-to-images-on-macos
[CW-310] Add constraints to images on macos
This commit is contained in:
commit
770e3b6f52
4 changed files with 351 additions and 343 deletions
|
@ -1,6 +1,7 @@
|
||||||
import 'package:cake_wallet/entities/generate_name.dart';
|
import 'package:cake_wallet/entities/generate_name.dart';
|
||||||
import 'package:cake_wallet/routes.dart';
|
import 'package:cake_wallet/routes.dart';
|
||||||
import 'package:cake_wallet/themes/theme_base.dart';
|
import 'package:cake_wallet/themes/theme_base.dart';
|
||||||
|
import 'package:cake_wallet/utils/responsive_layout_util.dart';
|
||||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||||
|
@ -24,18 +25,14 @@ class NewWalletPage extends BasePage {
|
||||||
|
|
||||||
final walletNameImage = Image.asset('assets/images/wallet_name.png');
|
final walletNameImage = Image.asset('assets/images/wallet_name.png');
|
||||||
|
|
||||||
final walletNameLightImage =
|
final walletNameLightImage = Image.asset('assets/images/wallet_name_light.png');
|
||||||
Image.asset('assets/images/wallet_name_light.png');
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get title => S.current.new_wallet;
|
String get title => S.current.new_wallet;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget body(BuildContext context) => WalletNameForm(
|
Widget body(BuildContext context) => WalletNameForm(
|
||||||
_walletNewVM,
|
_walletNewVM, currentTheme.type == ThemeType.dark ? walletNameImage : walletNameLightImage);
|
||||||
currentTheme.type == ThemeType.dark
|
|
||||||
? walletNameImage
|
|
||||||
: walletNameLightImage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class WalletNameForm extends StatefulWidget {
|
class WalletNameForm extends StatefulWidget {
|
||||||
|
@ -50,9 +47,9 @@ class WalletNameForm extends StatefulWidget {
|
||||||
|
|
||||||
class _WalletNameFormState extends State<WalletNameForm> {
|
class _WalletNameFormState extends State<WalletNameForm> {
|
||||||
_WalletNameFormState(this._walletNewVM)
|
_WalletNameFormState(this._walletNewVM)
|
||||||
: _formKey = GlobalKey<FormState>(),
|
: _formKey = GlobalKey<FormState>(),
|
||||||
_languageSelectorKey = GlobalKey<SeedLanguageSelectorState>(),
|
_languageSelectorKey = GlobalKey<SeedLanguageSelectorState>(),
|
||||||
_controller = TextEditingController();
|
_controller = TextEditingController();
|
||||||
|
|
||||||
static const aspectRatioImage = 1.22;
|
static const aspectRatioImage = 1.22;
|
||||||
|
|
||||||
|
@ -64,11 +61,9 @@ class _WalletNameFormState extends State<WalletNameForm> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
_stateReaction ??=
|
_stateReaction ??= reaction((_) => _walletNewVM.state, (ExecutionState state) {
|
||||||
reaction((_) => _walletNewVM.state, (ExecutionState state) {
|
|
||||||
if (state is ExecutedSuccessfullyState) {
|
if (state is ExecutedSuccessfullyState) {
|
||||||
Navigator.of(context)
|
Navigator.of(context).pushNamed(Routes.preSeed, arguments: _walletNewVM.type);
|
||||||
.pushNamed(Routes.preSeed, arguments: _walletNewVM.type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state is FailureState) {
|
if (state is FailureState) {
|
||||||
|
@ -90,140 +85,144 @@ class _WalletNameFormState extends State<WalletNameForm> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Padding(
|
||||||
padding: EdgeInsets.only(top: 24),
|
padding: EdgeInsets.only(top: 24),
|
||||||
child: ScrollableWithBottomSection(
|
child: ScrollableWithBottomSection(
|
||||||
contentPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
contentPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
||||||
content:
|
content: Center(
|
||||||
Column(crossAxisAlignment: CrossAxisAlignment.center, children: [
|
child: ConstrainedBox(
|
||||||
Padding(
|
constraints:
|
||||||
padding: EdgeInsets.only(left: 12, right: 12),
|
BoxConstraints(maxWidth: ResponsiveLayoutUtil.kDesktopMaxWidthConstraint),
|
||||||
child: AspectRatio(
|
child: Column(
|
||||||
aspectRatio: aspectRatioImage,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
child:
|
children: [
|
||||||
FittedBox(child: widget.walletImage, fit: BoxFit.fill)),
|
Padding(
|
||||||
),
|
padding: EdgeInsets.only(left: 12, right: 12),
|
||||||
Padding(
|
child: AspectRatio(
|
||||||
padding: EdgeInsets.only(top: 24),
|
aspectRatio: aspectRatioImage,
|
||||||
child: Form(
|
child: FittedBox(child: widget.walletImage, fit: BoxFit.fill)),
|
||||||
key: _formKey,
|
),
|
||||||
child: Stack(
|
Padding(
|
||||||
alignment: Alignment.centerRight,
|
padding: EdgeInsets.only(top: 24),
|
||||||
children: [
|
child: Form(
|
||||||
TextFormField(
|
key: _formKey,
|
||||||
onChanged: (value) => _walletNewVM.name = value,
|
child: Stack(
|
||||||
controller: _controller,
|
alignment: Alignment.centerRight,
|
||||||
textAlign: TextAlign.center,
|
children: [
|
||||||
style: TextStyle(
|
TextFormField(
|
||||||
fontSize: 20.0,
|
onChanged: (value) => _walletNewVM.name = value,
|
||||||
fontWeight: FontWeight.w600,
|
controller: _controller,
|
||||||
color:
|
textAlign: TextAlign.center,
|
||||||
Theme.of(context).primaryTextTheme!.headline6!.color!),
|
style: TextStyle(
|
||||||
decoration: InputDecoration(
|
fontSize: 20.0,
|
||||||
hintStyle: TextStyle(
|
fontWeight: FontWeight.w600,
|
||||||
fontSize: 18.0,
|
color: Theme.of(context).primaryTextTheme!.headline6!.color!),
|
||||||
fontWeight: FontWeight.w500,
|
decoration: InputDecoration(
|
||||||
color: Theme.of(context)
|
hintStyle: TextStyle(
|
||||||
.accentTextTheme!
|
fontSize: 18.0,
|
||||||
.headline2!
|
fontWeight: FontWeight.w500,
|
||||||
.color!),
|
color: Theme.of(context).accentTextTheme!.headline2!.color!),
|
||||||
hintText: S.of(context).wallet_name,
|
hintText: S.of(context).wallet_name,
|
||||||
focusedBorder: UnderlineInputBorder(
|
focusedBorder: UnderlineInputBorder(
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.accentTextTheme!
|
.accentTextTheme!
|
||||||
.headline2!
|
.headline2!
|
||||||
.decorationColor!,
|
.decorationColor!,
|
||||||
width: 1.0)),
|
width: 1.0)),
|
||||||
enabledBorder: UnderlineInputBorder(
|
enabledBorder: UnderlineInputBorder(
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.accentTextTheme!
|
.accentTextTheme!
|
||||||
.headline2!
|
.headline2!
|
||||||
.decorationColor!,
|
.decorationColor!,
|
||||||
width: 1.0),
|
width: 1.0),
|
||||||
),
|
),
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final rName = await generateName();
|
final rName = await generateName();
|
||||||
FocusManager.instance.primaryFocus?.unfocus();
|
FocusManager.instance.primaryFocus?.unfocus();
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_controller.text = rName;
|
_controller.text = rName;
|
||||||
_walletNewVM.name = rName;
|
_walletNewVM.name = rName;
|
||||||
_controller.selection = TextSelection.fromPosition(
|
_controller.selection = TextSelection.fromPosition(
|
||||||
TextPosition(offset: _controller.text.length));
|
TextPosition(offset: _controller.text.length));
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
icon: Container(
|
icon: Container(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(6.0),
|
borderRadius: BorderRadius.circular(6.0),
|
||||||
color: Theme.of(context).hintColor,
|
color: Theme.of(context).hintColor,
|
||||||
),
|
),
|
||||||
width: 34,
|
width: 34,
|
||||||
height: 34,
|
height: 34,
|
||||||
child: Image.asset(
|
child: Image.asset(
|
||||||
'assets/images/refresh_icon.png',
|
'assets/images/refresh_icon.png',
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.primaryTextTheme!
|
.primaryTextTheme!
|
||||||
.headline4!
|
.headline4!
|
||||||
.decorationColor!,
|
.decorationColor!,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
validator: WalletNameValidator(),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
validator: WalletNameValidator(),
|
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
if (_walletNewVM.hasLanguageSelector) ...[
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(top: 40),
|
||||||
|
child: Text(
|
||||||
|
S.of(context).seed_language_choose,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16.0,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: Theme.of(context).primaryTextTheme!.headline6!.color!),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(top: 24),
|
||||||
|
child: SeedLanguageSelector(
|
||||||
|
key: _languageSelectorKey, initialSelected: defaultSeedLanguage),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (_walletNewVM.hasLanguageSelector) ...[
|
),
|
||||||
Padding(
|
bottomSectionPadding: EdgeInsets.all(24),
|
||||||
padding: EdgeInsets.only(top: 40),
|
bottomSection: ConstrainedBox(
|
||||||
child: Text(
|
constraints: BoxConstraints(maxWidth: ResponsiveLayoutUtil.kDesktopMaxWidthConstraint),
|
||||||
S.of(context).seed_language_choose,
|
child: Column(
|
||||||
textAlign: TextAlign.center,
|
children: [
|
||||||
style: TextStyle(
|
Observer(
|
||||||
fontSize: 16.0,
|
builder: (context) {
|
||||||
fontWeight: FontWeight.w500,
|
return LoadingPrimaryButton(
|
||||||
color: Theme.of(context).primaryTextTheme!.headline6!.color!),
|
onPressed: _confirmForm,
|
||||||
|
text: S.of(context).seed_language_next,
|
||||||
|
color: Colors.green,
|
||||||
|
textColor: Colors.white,
|
||||||
|
isLoading: _walletNewVM.state is IsExecutingState,
|
||||||
|
isDisabled: _walletNewVM.name.isEmpty,
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 25),
|
||||||
Padding(
|
GestureDetector(
|
||||||
padding: EdgeInsets.only(top: 24),
|
onTap: () {
|
||||||
child: SeedLanguageSelector(
|
Navigator.of(context)
|
||||||
key: _languageSelectorKey,
|
.pushNamed(Routes.advancedPrivacySettings, arguments: _walletNewVM.type);
|
||||||
initialSelected: defaultSeedLanguage),
|
},
|
||||||
)
|
child: Text(S.of(context).advanced_privacy_settings),
|
||||||
]
|
),
|
||||||
]),
|
],
|
||||||
bottomSectionPadding:
|
),
|
||||||
EdgeInsets.all(24),
|
|
||||||
bottomSection: Column(
|
|
||||||
children: [
|
|
||||||
Observer(
|
|
||||||
builder: (context) {
|
|
||||||
return LoadingPrimaryButton(
|
|
||||||
onPressed: _confirmForm,
|
|
||||||
text: S.of(context).seed_language_next,
|
|
||||||
color: Colors.green,
|
|
||||||
textColor: Colors.white,
|
|
||||||
isLoading: _walletNewVM.state is IsExecutingState,
|
|
||||||
isDisabled: _walletNewVM.name.isEmpty,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(height: 25),
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
Navigator.of(context)
|
|
||||||
.pushNamed(Routes.advancedPrivacySettings, arguments: _walletNewVM.type);
|
|
||||||
},
|
|
||||||
child: Text(S.of(context).advanced_privacy_settings),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:cake_wallet/utils/responsive_layout_util.dart';
|
||||||
import 'package:cw_core/wallet_type.dart';
|
import 'package:cw_core/wallet_type.dart';
|
||||||
import 'package:cake_wallet/themes/theme_base.dart';
|
import 'package:cake_wallet/themes/theme_base.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
@ -13,23 +14,19 @@ class NewWalletTypePage extends BasePage {
|
||||||
|
|
||||||
final void Function(BuildContext, WalletType) onTypeSelected;
|
final void Function(BuildContext, WalletType) onTypeSelected;
|
||||||
final walletTypeImage = Image.asset('assets/images/wallet_type.png');
|
final walletTypeImage = Image.asset('assets/images/wallet_type.png');
|
||||||
final walletTypeLightImage =
|
final walletTypeLightImage = Image.asset('assets/images/wallet_type_light.png');
|
||||||
Image.asset('assets/images/wallet_type_light.png');
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get title => S.current.wallet_list_restore_wallet;
|
String get title => S.current.wallet_list_restore_wallet;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget body(BuildContext context) => WalletTypeForm(
|
Widget body(BuildContext context) => WalletTypeForm(
|
||||||
onTypeSelected: onTypeSelected,
|
onTypeSelected: onTypeSelected,
|
||||||
walletImage: currentTheme.type == ThemeType.dark
|
walletImage: currentTheme.type == ThemeType.dark ? walletTypeImage : walletTypeLightImage);
|
||||||
? walletTypeImage
|
|
||||||
: walletTypeLightImage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class WalletTypeForm extends StatefulWidget {
|
class WalletTypeForm extends StatefulWidget {
|
||||||
WalletTypeForm({required this.onTypeSelected,
|
WalletTypeForm({required this.onTypeSelected, required this.walletImage});
|
||||||
required this.walletImage});
|
|
||||||
|
|
||||||
final void Function(BuildContext, WalletType) onTypeSelected;
|
final void Function(BuildContext, WalletType) onTypeSelected;
|
||||||
final Image walletImage;
|
final Image walletImage;
|
||||||
|
@ -39,22 +36,16 @@ class WalletTypeForm extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class WalletTypeFormState extends State<WalletTypeForm> {
|
class WalletTypeFormState extends State<WalletTypeForm> {
|
||||||
WalletTypeFormState()
|
WalletTypeFormState() : types = availableWalletTypes;
|
||||||
: types = availableWalletTypes;
|
|
||||||
|
|
||||||
static const aspectRatioImage = 1.22;
|
static const aspectRatioImage = 1.22;
|
||||||
|
|
||||||
final moneroIcon =
|
final moneroIcon = Image.asset('assets/images/monero_logo.png', height: 24, width: 24);
|
||||||
Image.asset('assets/images/monero_logo.png', height: 24, width: 24);
|
final bitcoinIcon = Image.asset('assets/images/bitcoin.png', height: 24, width: 24);
|
||||||
final bitcoinIcon =
|
final litecoinIcon = Image.asset('assets/images/litecoin_icon.png', height: 24, width: 24);
|
||||||
Image.asset('assets/images/bitcoin.png', height: 24, width: 24);
|
|
||||||
final litecoinIcon =
|
|
||||||
Image.asset('assets/images/litecoin_icon.png', height: 24, width: 24);
|
|
||||||
final walletTypeImage = Image.asset('assets/images/wallet_type.png');
|
final walletTypeImage = Image.asset('assets/images/wallet_type.png');
|
||||||
final walletTypeLightImage =
|
final walletTypeLightImage = Image.asset('assets/images/wallet_type_light.png');
|
||||||
Image.asset('assets/images/wallet_type_light.png');
|
final havenIcon = Image.asset('assets/images/haven_logo.png', height: 24, width: 24);
|
||||||
final havenIcon =
|
|
||||||
Image.asset('assets/images/haven_logo.png', height: 24, width: 24);
|
|
||||||
|
|
||||||
WalletType? selected;
|
WalletType? selected;
|
||||||
List<WalletType> types;
|
List<WalletType> types;
|
||||||
|
@ -69,43 +60,51 @@ class WalletTypeFormState extends State<WalletTypeForm> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ScrollableWithBottomSection(
|
return ScrollableWithBottomSection(
|
||||||
contentPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
contentPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
||||||
content: Column(
|
content: Center(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
child: ConstrainedBox(
|
||||||
children: <Widget>[
|
constraints: BoxConstraints(maxWidth: ResponsiveLayoutUtil.kDesktopMaxWidthConstraint),
|
||||||
Padding(
|
child: Column(
|
||||||
padding: EdgeInsets.only(left: 12, right: 12),
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
child: AspectRatio(
|
children: <Widget>[
|
||||||
aspectRatio: aspectRatioImage,
|
Padding(
|
||||||
child: FittedBox(child: widget.walletImage, fit: BoxFit.fill)),
|
padding: EdgeInsets.only(left: 12, right: 12),
|
||||||
|
child: AspectRatio(
|
||||||
|
aspectRatio: aspectRatioImage,
|
||||||
|
child: FittedBox(child: widget.walletImage, fit: BoxFit.fill)),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(top: 48),
|
||||||
|
child: Text(
|
||||||
|
S.of(context).choose_wallet_currency,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
color: Theme.of(context).primaryTextTheme.headline6!.color!),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
...types.map((type) => Padding(
|
||||||
|
padding: EdgeInsets.only(top: 24),
|
||||||
|
child: SelectButton(
|
||||||
|
image: _iconFor(type),
|
||||||
|
text: walletTypeToDisplayName(type),
|
||||||
|
isSelected: selected == type,
|
||||||
|
onTap: () => setState(() => selected = type)),
|
||||||
|
))
|
||||||
|
],
|
||||||
),
|
),
|
||||||
Padding(
|
),
|
||||||
padding: EdgeInsets.only(top: 48),
|
|
||||||
child: Text(
|
|
||||||
S.of(context).choose_wallet_currency,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color: Theme.of(context).primaryTextTheme.headline6!.color!),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...types.map((type) => Padding(
|
|
||||||
padding: EdgeInsets.only(top: 24),
|
|
||||||
child: SelectButton(
|
|
||||||
image: _iconFor(type),
|
|
||||||
text: walletTypeToDisplayName(type),
|
|
||||||
isSelected: selected == type,
|
|
||||||
onTap: () => setState(() => selected = type)),
|
|
||||||
))
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
||||||
bottomSection: PrimaryButton(
|
bottomSection: ConstrainedBox(
|
||||||
onPressed: () => onTypeSelected(),
|
constraints: BoxConstraints(maxWidth: ResponsiveLayoutUtil.kDesktopMaxWidthConstraint),
|
||||||
text: S.of(context).seed_language_next,
|
child: PrimaryButton(
|
||||||
color: Theme.of(context).accentTextTheme.bodyText1!.color!,
|
onPressed: () => onTypeSelected(),
|
||||||
textColor: Colors.white,
|
text: S.of(context).seed_language_next,
|
||||||
isDisabled: selected == null,
|
color: Theme.of(context).accentTextTheme.bodyText1!.color!,
|
||||||
|
textColor: Colors.white,
|
||||||
|
isDisabled: selected == null,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -121,7 +120,8 @@ class WalletTypeFormState extends State<WalletTypeForm> {
|
||||||
case WalletType.haven:
|
case WalletType.haven:
|
||||||
return havenIcon;
|
return havenIcon;
|
||||||
default:
|
default:
|
||||||
throw Exception('_iconFor: Incorrect Wallet Type. Cannot find icon for Wallet Type: ${type.toString()}');
|
throw Exception(
|
||||||
|
'_iconFor: Incorrect Wallet Type. Cannot find icon for Wallet Type: ${type.toString()}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:cake_wallet/utils/responsive_layout_util.dart';
|
||||||
import 'package:cake_wallet/utils/show_bar.dart';
|
import 'package:cake_wallet/utils/show_bar.dart';
|
||||||
import 'package:another_flushbar/flushbar.dart';
|
import 'package:another_flushbar/flushbar.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
@ -5,14 +6,14 @@ import 'package:cake_wallet/generated/i18n.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
class PinCodeWidget extends StatefulWidget {
|
class PinCodeWidget extends StatefulWidget {
|
||||||
PinCodeWidget(
|
PinCodeWidget({
|
||||||
{required Key key,
|
required Key key,
|
||||||
required this.onFullPin,
|
required this.onFullPin,
|
||||||
required this.initialPinLength,
|
required this.initialPinLength,
|
||||||
required this.onChangedPin,
|
required this.onChangedPin,
|
||||||
required this.hasLengthSwitcher,
|
required this.hasLengthSwitcher,
|
||||||
this.onChangedPinLength,})
|
this.onChangedPinLength,
|
||||||
: super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final void Function(String pin, PinCodeState state) onFullPin;
|
final void Function(String pin, PinCodeState state) onFullPin;
|
||||||
final void Function(String pin) onChangedPin;
|
final void Function(String pin) onChangedPin;
|
||||||
|
@ -26,10 +27,10 @@ class PinCodeWidget extends StatefulWidget {
|
||||||
|
|
||||||
class PinCodeState<T extends PinCodeWidget> extends State<T> {
|
class PinCodeState<T extends PinCodeWidget> extends State<T> {
|
||||||
PinCodeState()
|
PinCodeState()
|
||||||
: _aspectRatio = 0,
|
: _aspectRatio = 0,
|
||||||
pinLength = 0,
|
pinLength = 0,
|
||||||
pin = '',
|
pin = '',
|
||||||
title = '';
|
title = '';
|
||||||
static const defaultPinLength = fourPinLength;
|
static const defaultPinLength = fourPinLength;
|
||||||
static const sixPinLength = 6;
|
static const sixPinLength = 6;
|
||||||
static const fourPinLength = 4;
|
static const fourPinLength = 4;
|
||||||
|
@ -76,8 +77,7 @@ class PinCodeState<T extends PinCodeWidget> extends State<T> {
|
||||||
void setDefaultPinLength() => changePinLength(widget.initialPinLength);
|
void setDefaultPinLength() => changePinLength(widget.initialPinLength);
|
||||||
|
|
||||||
void calculateAspectRatio() {
|
void calculateAspectRatio() {
|
||||||
final renderBox =
|
final renderBox = _gridViewKey.currentContext!.findRenderObject() as RenderBox;
|
||||||
_gridViewKey.currentContext!.findRenderObject() as RenderBox;
|
|
||||||
final cellWidth = renderBox.size.width / 3;
|
final cellWidth = renderBox.size.width / 3;
|
||||||
final cellHeight = renderBox.size.height / 4;
|
final cellHeight = renderBox.size.height / 4;
|
||||||
|
|
||||||
|
@ -90,8 +90,7 @@ class PinCodeState<T extends PinCodeWidget> extends State<T> {
|
||||||
|
|
||||||
void changeProcessText(String text) {
|
void changeProcessText(String text) {
|
||||||
hideProgressText();
|
hideProgressText();
|
||||||
_progressBar = createBar<void>(text, duration: null)
|
_progressBar = createBar<void>(text, duration: null)..show(_key.currentContext!);
|
||||||
..show(_key.currentContext!);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void close() {
|
void close() {
|
||||||
|
@ -105,8 +104,8 @@ class PinCodeState<T extends PinCodeWidget> extends State<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => Scaffold(
|
Widget build(BuildContext context) =>
|
||||||
key: _key, body: body(context), resizeToAvoidBottomInset: false);
|
Scaffold(key: _key, body: body(context), resizeToAvoidBottomInset: false);
|
||||||
|
|
||||||
Widget body(BuildContext context) {
|
Widget body(BuildContext context) {
|
||||||
final deleteIconImage = Image.asset(
|
final deleteIconImage = Image.asset(
|
||||||
|
@ -136,41 +135,42 @@ class PinCodeState<T extends PinCodeWidget> extends State<T> {
|
||||||
child: Container(
|
child: Container(
|
||||||
color: Theme.of(context).backgroundColor,
|
color: Theme.of(context).backgroundColor,
|
||||||
padding: EdgeInsets.only(left: 40.0, right: 40.0, bottom: 40.0),
|
padding: EdgeInsets.only(left: 40.0, right: 40.0, bottom: 40.0),
|
||||||
child: Column(children: <Widget>[
|
child: Column(
|
||||||
Spacer(flex: 2),
|
children: <Widget>[
|
||||||
Text(title,
|
Spacer(flex: 2),
|
||||||
style: TextStyle(
|
Text(title,
|
||||||
fontSize: 20,
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.w500,
|
fontSize: 20,
|
||||||
color: Theme.of(context).primaryTextTheme!.headline6!.color!)),
|
fontWeight: FontWeight.w500,
|
||||||
Spacer(flex: 3),
|
color: Theme.of(context).primaryTextTheme!.headline6!.color!)),
|
||||||
Container(
|
Spacer(flex: 3),
|
||||||
width: 180,
|
Container(
|
||||||
child: Row(
|
width: 180,
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
child: Row(
|
||||||
children: List.generate(pinLength, (index) {
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
const size = 10.0;
|
children: List.generate(pinLength, (index) {
|
||||||
final isFilled = pin.length > index ? pin[index] != null : false;
|
const size = 10.0;
|
||||||
|
final isFilled = pin.length > index ? pin[index] != null : false;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
width: size,
|
width: size,
|
||||||
height: size,
|
height: size,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
color: isFilled
|
color: isFilled
|
||||||
? Theme.of(context).primaryTextTheme!.headline6!.color!
|
? Theme.of(context).primaryTextTheme!.headline6!.color!
|
||||||
: Theme.of(context)
|
: Theme.of(context)
|
||||||
.accentTextTheme!
|
.accentTextTheme!
|
||||||
.bodyText2!
|
.bodyText2!
|
||||||
.color!
|
.color!
|
||||||
.withOpacity(0.25),
|
.withOpacity(0.25),
|
||||||
));
|
));
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
Spacer(flex: 2),
|
||||||
Spacer(flex: 2),
|
if (widget.hasLengthSwitcher) ...[
|
||||||
if (widget.hasLengthSwitcher) ...[
|
TextButton(
|
||||||
TextButton(
|
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
changePinLength(pinLength == PinCodeState.fourPinLength
|
changePinLength(pinLength == PinCodeState.fourPinLength
|
||||||
? PinCodeState.sixPinLength
|
? PinCodeState.sixPinLength
|
||||||
|
@ -181,111 +181,119 @@ class PinCodeState<T extends PinCodeWidget> extends State<T> {
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 14.0,
|
fontSize: 14.0,
|
||||||
fontWeight: FontWeight.normal,
|
fontWeight: FontWeight.normal,
|
||||||
color: Theme.of(context)
|
color: Theme.of(context).accentTextTheme!.bodyText2!.decorationColor!),
|
||||||
.accentTextTheme!
|
),
|
||||||
.bodyText2!
|
)
|
||||||
.decorationColor!),
|
],
|
||||||
))
|
Spacer(flex: 1),
|
||||||
],
|
Flexible(
|
||||||
Spacer(flex: 1),
|
|
||||||
Flexible(
|
|
||||||
flex: 24,
|
flex: 24,
|
||||||
child: Container(
|
child: Center(
|
||||||
key: _gridViewKey,
|
child: ConstrainedBox(
|
||||||
child: _aspectRatio > 0
|
constraints: BoxConstraints(
|
||||||
? GridView.count(
|
maxWidth: ResponsiveLayoutUtil.kDesktopMaxWidthConstraint,
|
||||||
shrinkWrap: true,
|
),
|
||||||
crossAxisCount: 3,
|
child: Container(
|
||||||
childAspectRatio: _aspectRatio,
|
key: _gridViewKey,
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
child: _aspectRatio > 0
|
||||||
children: List.generate(12, (index) {
|
? ScrollConfiguration(
|
||||||
const double marginRight = 15;
|
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
|
||||||
const double marginLeft = 15;
|
child: GridView.count(
|
||||||
|
shrinkWrap: true,
|
||||||
|
crossAxisCount: 3,
|
||||||
|
childAspectRatio: _aspectRatio,
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
children: List.generate(12, (index) {
|
||||||
|
const double marginRight = 15;
|
||||||
|
const double marginLeft = 15;
|
||||||
|
|
||||||
if (index == 9) {
|
if (index == 9) {
|
||||||
return Container(
|
return Container(
|
||||||
margin: EdgeInsets.only(
|
margin: EdgeInsets.only(left: marginLeft, right: marginRight),
|
||||||
left: marginLeft, right: marginRight),
|
child: TextButton(
|
||||||
child: TextButton(
|
onPressed: () => null,
|
||||||
onPressed: () => null,
|
// (widget.hasLengthSwitcher ||
|
||||||
// (widget.hasLengthSwitcher ||
|
// !settingsStore
|
||||||
// !settingsStore
|
// .allowBiometricalAuthentication)
|
||||||
// .allowBiometricalAuthentication)
|
// ? null
|
||||||
// ? null
|
// : () {
|
||||||
// : () {
|
// FIXME
|
||||||
// FIXME
|
// if (authStore != null) {
|
||||||
// if (authStore != null) {
|
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
// final biometricAuth = BiometricAuth();
|
||||||
// final biometricAuth = BiometricAuth();
|
// biometricAuth.isAuthenticated().then(
|
||||||
// biometricAuth.isAuthenticated().then(
|
// (isAuth) {
|
||||||
// (isAuth) {
|
// if (isAuth) {
|
||||||
// if (isAuth) {
|
// authStore.biometricAuth();
|
||||||
// authStore.biometricAuth();
|
// _key.currentState.showSnackBar(
|
||||||
// _key.currentState.showSnackBar(
|
// SnackBar(
|
||||||
// SnackBar(
|
// content: Text(S.of(context).authenticated),
|
||||||
// content: Text(S.of(context).authenticated),
|
// backgroundColor: Colors.green,
|
||||||
// backgroundColor: Colors.green,
|
// ),
|
||||||
// ),
|
// );
|
||||||
// );
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// );
|
||||||
// );
|
// });
|
||||||
// });
|
// }
|
||||||
// }
|
// },
|
||||||
// },
|
// FIX-ME: Style
|
||||||
// FIX-ME: Style
|
//color: Theme.of(context).backgroundColor,
|
||||||
//color: Theme.of(context).backgroundColor,
|
//shape: CircleBorder(),
|
||||||
//shape: CircleBorder(),
|
child: Container()
|
||||||
child: Container()
|
// (widget.hasLengthSwitcher ||
|
||||||
// (widget.hasLengthSwitcher ||
|
// !settingsStore
|
||||||
// !settingsStore
|
// .allowBiometricalAuthentication)
|
||||||
// .allowBiometricalAuthentication)
|
// ? Offstage()
|
||||||
// ? Offstage()
|
// : faceImage,
|
||||||
// : faceImage,
|
),
|
||||||
|
);
|
||||||
|
} else if (index == 10) {
|
||||||
|
index = 0;
|
||||||
|
} else if (index == 11) {
|
||||||
|
return Container(
|
||||||
|
margin: EdgeInsets.only(left: marginLeft, right: marginRight),
|
||||||
|
child: TextButton(
|
||||||
|
onPressed: () => _pop(),
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
backgroundColor: Theme.of(context).backgroundColor,
|
||||||
|
shape: CircleBorder(),
|
||||||
|
),
|
||||||
|
child: deleteIconImage,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else if (index == 10) {
|
} else {
|
||||||
index = 0;
|
index++;
|
||||||
} else if (index == 11) {
|
}
|
||||||
return Container(
|
|
||||||
margin: EdgeInsets.only(
|
|
||||||
left: marginLeft, right: marginRight),
|
|
||||||
child: TextButton(
|
|
||||||
onPressed: () => _pop(),
|
|
||||||
style: TextButton.styleFrom(
|
|
||||||
backgroundColor: Theme.of(context).backgroundColor,
|
|
||||||
shape: CircleBorder(),
|
|
||||||
),
|
|
||||||
child: deleteIconImage,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
margin: EdgeInsets.only(
|
margin: EdgeInsets.only(left: marginLeft, right: marginRight),
|
||||||
left: marginLeft, right: marginRight),
|
child: TextButton(
|
||||||
child: TextButton(
|
onPressed: () => _push(index),
|
||||||
onPressed: () => _push(index),
|
style: TextButton.styleFrom(
|
||||||
style: TextButton.styleFrom(
|
backgroundColor: Theme.of(context).backgroundColor,
|
||||||
backgroundColor: Theme.of(context).backgroundColor,
|
shape: CircleBorder(),
|
||||||
shape: CircleBorder(),
|
),
|
||||||
),
|
child: Text('$index',
|
||||||
child: Text('$index',
|
style: TextStyle(
|
||||||
style: TextStyle(
|
fontSize: 30.0,
|
||||||
fontSize: 30.0,
|
fontWeight: FontWeight.w600,
|
||||||
fontWeight: FontWeight.w600,
|
color: Theme.of(context)
|
||||||
color: Theme.of(context)
|
.primaryTextTheme!
|
||||||
.primaryTextTheme!
|
.headline6!
|
||||||
.headline6!
|
.color!)),
|
||||||
.color!)),
|
),
|
||||||
),
|
);
|
||||||
);
|
}),
|
||||||
}),
|
),
|
||||||
)
|
)
|
||||||
: null))
|
: null,
|
||||||
]),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class ResponsiveLayoutUtil {
|
class ResponsiveLayoutUtil {
|
||||||
static const double _kMobileThreshold = 900;
|
static const double _kMobileThreshold = 900;
|
||||||
|
static const double kDesktopMaxWidthConstraint = 400;
|
||||||
|
|
||||||
const ResponsiveLayoutUtil._();
|
const ResponsiveLayoutUtil._();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue