| 1 | import 'package:cake_wallet/core/address_resolver/yat/yat_store.dart'; |
| 2 | import 'package:cake_wallet/src/screens/yat/widgets/first_introduction.dart'; |
| 3 | import 'package:cake_wallet/src/screens/yat/widgets/second_introduction.dart'; |
| 4 | import 'package:cake_wallet/src/screens/yat/widgets/third_introduction.dart'; |
| 5 | import 'package:cake_wallet/src/screens/yat/widgets/yat_close_button.dart'; |
| 6 | import 'package:cake_wallet/src/widgets/alert_background.dart'; |
| 7 | import 'package:cake_wallet/src/widgets/primary_button.dart'; |
| 8 | import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; |
| 9 | import 'package:flutter/material.dart'; |
| 10 | import 'package:animate_do/animate_do.dart'; |
| 11 | import 'package:flutter_mobx/flutter_mobx.dart'; |
| 12 | import 'package:url_launcher/url_launcher.dart'; |
| 13 | import 'package:cake_wallet/generated/i18n.dart'; |
| 14 | |
| 15 | class YatPopup extends StatelessWidget { |
| 16 | YatPopup({required this.dashboardViewModel, required this.onClose}) |
| 17 | : baseUrl = YatLink.isDevMode ? YatLink.baseDevUrl : YatLink.baseReleaseUrl; |
| 18 | |
| 19 | static const durationInMilliseconds = 250; |
| 20 | |
| 21 | final DashboardViewModel dashboardViewModel; |
| 22 | final VoidCallback onClose; |
| 23 | final String baseUrl; |
| 24 | final image = Image.asset('assets/images/emoji_popup.png'); |
| 25 | |
| 26 | @override |
| 27 | Widget build(BuildContext context) { |
| 28 | final screenWidth = MediaQuery.of(context).size.width; |
| 29 | |
| 30 | return Stack( |
| 31 | clipBehavior: Clip.none, |
| 32 | alignment: Alignment.bottomCenter, |
| 33 | children: [ |
| 34 | AlertBackground(child: Container()), |
| 35 | SlideInUp( |
| 36 | from: 420, |
| 37 | duration: Duration(milliseconds: durationInMilliseconds), |
| 38 | child: ClipRRect( |
| 39 | borderRadius: |
| 40 | BorderRadius.only(topLeft: Radius.circular(24), topRight: Radius.circular(24)), |
| 41 | child: Container( |
| 42 | height: 420, |
| 43 | color: Theme.of(context).colorScheme.surfaceContainer, |
| 44 | padding: EdgeInsets.fromLTRB(24, 15, 24, 24), |
| 45 | child: Column( |
| 46 | mainAxisSize: MainAxisSize.max, |
| 47 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 48 | children: [ |
| 49 | Column(children: [ |
| 50 | Row( |
| 51 | mainAxisSize: MainAxisSize.max, |
| 52 | mainAxisAlignment: MainAxisAlignment.end, |
| 53 | children: [YatCloseButton(onClose: onClose)]), |
| 54 | Row( |
| 55 | mainAxisSize: MainAxisSize.max, |
| 56 | mainAxisAlignment: MainAxisAlignment.center, |
| 57 | children: [ |
| 58 | Container( |
| 59 | height: 64, |
| 60 | width: 165, |
| 61 | alignment: Alignment.center, |
| 62 | decoration: BoxDecoration( |
| 63 | color: Theme.of(context).colorScheme.surfaceContainer, |
| 64 | borderRadius: BorderRadius.all(Radius.circular(32)), |
| 65 | boxShadow: [ |
| 66 | BoxShadow( |
| 67 | color: Theme.of(context) |
| 68 | .colorScheme |
| 69 | .onSurface |
| 70 | .withOpacity(0.05), |
| 71 | blurRadius: 15, |
| 72 | offset: Offset(0, 5)) |
| 73 | ]), |
| 74 | child: image) |
| 75 | ]) |
| 76 | ]), |
| 77 | Container( |
| 78 | padding: EdgeInsets.only(left: 6, right: 6), |
| 79 | child: Column(children: [ |
| 80 | Text(S.of(context).yat_popup_title, |
| 81 | textAlign: TextAlign.center, |
| 82 | style: Theme.of(context).textTheme.bodyLarge?.copyWith( |
| 83 | fontSize: 24, |
| 84 | fontWeight: FontWeight.bold, |
| 85 | decoration: TextDecoration.none, |
| 86 | )), |
| 87 | Padding( |
| 88 | padding: EdgeInsets.only(top: 20), |
| 89 | child: Text(S.of(context).yat_popup_content, |
| 90 | textAlign: TextAlign.center, |
| 91 | style: Theme.of(context).textTheme.bodyMedium?.copyWith( |
| 92 | fontSize: 16, |
| 93 | decoration: TextDecoration.none, |
| 94 | ))) |
| 95 | ])), |
| 96 | PrimaryButton( |
| 97 | text: S.of(context).learn_more, |
| 98 | textColor: Theme.of(context).colorScheme.onPrimary, |
| 99 | color: Theme.of(context).colorScheme.primary, |
| 100 | onPressed: () => dashboardViewModel.isShowFirstYatIntroduction = true) |
| 101 | ], |
| 102 | ))), |
| 103 | ), |
| 104 | Observer( |
| 105 | builder: (_) => dashboardViewModel.isShowFirstYatIntroduction |
| 106 | ? SlideInRight( |
| 107 | from: screenWidth, |
| 108 | duration: Duration(milliseconds: durationInMilliseconds), |
| 109 | child: FirstIntroduction( |
| 110 | onClose: onClose, |
| 111 | onNext: () => dashboardViewModel.isShowSecondYatIntroduction = true)) |
| 112 | : Container()), |
| 113 | Observer( |
| 114 | builder: (_) => dashboardViewModel.isShowSecondYatIntroduction |
| 115 | ? SlideInRight( |
| 116 | from: screenWidth, |
| 117 | duration: Duration(milliseconds: durationInMilliseconds), |
| 118 | child: SecondIntroduction( |
| 119 | onClose: onClose, |
| 120 | onNext: () => dashboardViewModel.isShowThirdYatIntroduction = true)) |
| 121 | : Container()), |
| 122 | Observer( |
| 123 | builder: (_) => dashboardViewModel.isShowThirdYatIntroduction |
| 124 | ? SlideInRight( |
| 125 | from: screenWidth, |
| 126 | duration: Duration(milliseconds: durationInMilliseconds), |
| 127 | child: ThirdIntroduction( |
| 128 | onClose: onClose, |
| 129 | onGet: () { |
| 130 | var createNewYatUrl = YatLink.startFlowUrl; |
| 131 | final createNewYatUrlParameters = |
| 132 | dashboardViewModel.yatStore.defineQueryParameters(); |
| 133 | |
| 134 | if (createNewYatUrlParameters.isNotEmpty) { |
| 135 | createNewYatUrl += '?sub1=' + createNewYatUrlParameters; |
| 136 | } |
| 137 | |
| 138 | final uri = Uri.parse(createNewYatUrl); |
| 139 | launchUrl(uri, mode: LaunchMode.externalApplication); |
| 140 | }, |
| 141 | onConnect: () { |
| 142 | String url = baseUrl + YatLink.signInSuffix; |
| 143 | final parameters = dashboardViewModel.yatStore.defineQueryParameters(); |
| 144 | if (parameters.isNotEmpty) { |
| 145 | url += YatLink.queryParameter + parameters; |
| 146 | } |
| 147 | final uri = Uri.parse(url); |
| 148 | launchUrl(uri, mode: LaunchMode.externalApplication); |
| 149 | })) |
| 150 | : Container()) |
| 151 | ], |
| 152 | ); |
| 153 | } |
| 154 | } |