CAKE-356 | applied deep links to the app

wownero
OleksandrSobol 3 years ago
parent e787c96734
commit 39c40255d3

@ -29,6 +29,14 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="cakewallet"
android:host="y.at" />
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"

@ -57,6 +57,19 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>y.at</string>
<key>CFBundleURLSchemes</key>
<array>
<string>cakewallet</string>
</array>
</dict>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>

@ -1,6 +1,10 @@
import 'dart:async';
import 'package:cake_wallet/bitcoin/unspent_coins_info.dart';
import 'package:cake_wallet/entities/language_service.dart';
import 'package:cake_wallet/buy/order.dart';
import 'package:cake_wallet/store/yat_store.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hive/hive.dart';
@ -29,6 +33,7 @@ import 'package:cake_wallet/entities/template.dart';
import 'package:cake_wallet/exchange/trade.dart';
import 'package:cake_wallet/exchange/exchange_template.dart';
import 'package:cake_wallet/src/screens/root/root.dart';
import 'package:uni_links/uni_links.dart';
final navigatorKey = GlobalKey<NavigatorState>();
@ -168,7 +173,108 @@ Future<void> initialSetup(
monero_wallet.onStartup();
}
class App extends StatelessWidget {
class App extends StatefulWidget {
@override
AppState createState() => AppState();
}
class AppState extends State<App> with SingleTickerProviderStateMixin {
AppState() {
yatStore = getIt.get<YatStore>();
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
}
YatStore yatStore;
StreamSubscription stream;
@override
void initState() {
super.initState();
_handleIncomingLinks(yatStore);
_handleInitialUri(yatStore);
}
@override
void dispose() {
stream?.cancel();
super.dispose();
}
Future<void> _handleInitialUri(YatStore yatStore) async {
try {
final uri = await getInitialUri();
if (uri == null) {
print('Error: no initial uri');
return;
}
print('got initial uri: $uri');
if (!mounted) return;
yatStore.yatAddress = 'Yat address'; // FIXME
} catch (e) {
if (!mounted) return;
print(e.toString());
}
}
void _handleIncomingLinks(YatStore yatStore) {
if (!kIsWeb) {
stream = getUriLinksStream().listen((Uri uri) {
if (!mounted) return;
print('got uri: $uri');
yatStore.yatAddress = 'Yat address'; // FIXME
}, onError: (Object error) {
if (!mounted) return;
print('Error: $error');
});
}
}
@override
Widget build(BuildContext context) {
return Observer(builder: (BuildContext context) {
final settingsStore = getIt.get<AppStore>().settingsStore;
final statusBarColor = Colors.transparent;
final authenticationStore = getIt.get<AuthenticationStore>();
final initialRoute =
authenticationStore.state == AuthenticationState.denied
? Routes.disclaimer
: Routes.login;
final currentTheme = settingsStore.currentTheme;
final statusBarBrightness = currentTheme.type == ThemeType.dark
? Brightness.light
: Brightness.dark;
final statusBarIconBrightness = currentTheme.type == ThemeType.dark
? Brightness.light
: Brightness.dark;
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: statusBarColor,
statusBarBrightness: statusBarBrightness,
statusBarIconBrightness: statusBarIconBrightness));
return Root(
authenticationStore: authenticationStore,
navigatorKey: navigatorKey,
child: MaterialApp(
navigatorKey: navigatorKey,
debugShowCheckedModeBanner: false,
theme: settingsStore.theme,
localizationsDelegates: [
S.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
locale: Locale(settingsStore.languageCode),
onGenerateRoute: (settings) => Router.createRoute(settings),
initialRoute: initialRoute,
));
});
}
}
/*class App extends StatelessWidget {
App() {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
@ -216,4 +322,4 @@ class App extends StatelessWidget {
));
});
}
}
}*/

@ -6,9 +6,13 @@ import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/palette.dart';
import 'package:url_launcher/url_launcher.dart';
class YatAlert extends StatelessWidget {
static const aspectRatioImage = 1.133;
static const _baseUrl = 'https://yat.fyi';
static const _signInSuffix = '/sign-in';
static const _createSuffix = '/create';
final image = Image.asset('assets/images/yat_crypto.png');
@override
@ -81,8 +85,12 @@ class YatAlert extends StatelessWidget {
iconData: CupertinoIcons
.arrow_up_right_square,
mainAxisAlignment: MainAxisAlignment.end,
onPressed: () => Navigator.of(context)
.popAndPushNamed(Routes.yat, arguments: YatMode.create)),
onPressed: () {
//Navigator.of(context)
// .popAndPushNamed(Routes.yat, arguments: YatMode.create);
final url = _baseUrl + _createSuffix;
launch(url);
}),
Padding(
padding: EdgeInsets.only(top: 24),
child: PrimaryIconButton(
@ -95,8 +103,12 @@ class YatAlert extends StatelessWidget {
iconData: CupertinoIcons
.arrow_up_right_square,
mainAxisAlignment: MainAxisAlignment.end,
onPressed: () => Navigator.of(context)
.popAndPushNamed(Routes.yat, arguments: YatMode.connect))
onPressed: () {
//Navigator.of(context)
// .popAndPushNamed(Routes.yat, arguments: YatMode.connect);
final url = _baseUrl + _signInSuffix;
launch(url);
})
)
]
),

@ -69,7 +69,7 @@ class YatWebViewPageBodyState extends State<YatWebViewPageBody> {
super.initState();
_webViewkey = GlobalKey();
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
_fetchYatInfo();
WidgetsBinding.instance.addPostFrameCallback(_afterLayout);
}
@override
@ -88,6 +88,10 @@ class YatWebViewPageBodyState extends State<YatWebViewPageBody> {
setState(() => _webViewController = controller));
}
void _afterLayout(dynamic _) {
_fetchYatInfo();
}
void _fetchYatInfo() {
final keyword = 'dashboard';
_timer?.cancel();
@ -103,6 +107,7 @@ class YatWebViewPageBodyState extends State<YatWebViewPageBody> {
if (url.contains(keyword)) {
timer.cancel();
await yatViewModel.fetchCartInfo();
Navigator.of(context).pop();
}
} catch (e) {
print(e);

@ -956,6 +956,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
uni_links:
dependency: "direct main"
description:
name: uni_links
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.0"
unorm_dart:
dependency: "direct main"
description:

@ -57,6 +57,7 @@ dependencies:
smooth_page_indicator: ^0.2.0
webview_flutter: ^2.0.2
flutter_spinkit: ^5.0.0
uni_links: ^0.4.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.

Loading…
Cancel
Save