mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-09-01 08:04:07 +00:00
fix share link
This commit is contained in:
parent
60c553e53c
commit
dbe48b5802
4 changed files with 32 additions and 11 deletions
|
|
@ -161,6 +161,7 @@ class _AppMainWidgetState extends State<AppMainWidget> {
|
||||||
initAsync();
|
initAsync();
|
||||||
|
|
||||||
void handleShareLink(Uri uri) {
|
void handleShareLink(Uri uri) {
|
||||||
|
HomeViewState.pendingSharedLink = uri;
|
||||||
routerProvider.go(Routes.home);
|
routerProvider.go(Routes.home);
|
||||||
HomeViewState.streamHomeViewPageIndex.add(1);
|
HomeViewState.streamHomeViewPageIndex.add(1);
|
||||||
HomeViewState.streamSharedLink.add(uri);
|
HomeViewState.streamSharedLink.add(uri);
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ class CameraScannedOverlay extends StatelessWidget {
|
||||||
width: 150,
|
width: 150,
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: [
|
children: [
|
||||||
if (mainController.scannedUrl != null)
|
if (mainController.scannedUrl != null &&
|
||||||
|
mainController.scannedUrl!.isNotEmpty)
|
||||||
_buildScannedUrlTile(context, mainController.scannedUrl!),
|
_buildScannedUrlTile(context, mainController.scannedUrl!),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ class MainCameraController {
|
||||||
}
|
}
|
||||||
|
|
||||||
void onImageSend() {
|
void onImageSend() {
|
||||||
scannedUrl = '';
|
scannedUrl = null;
|
||||||
setState?.call();
|
setState?.call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,7 +210,9 @@ class MainCameraController {
|
||||||
await _initializeFuture;
|
await _initializeFuture;
|
||||||
} on CameraException catch (e) {
|
} on CameraException catch (e) {
|
||||||
// If specific image format is unsupported on this hardware, fallback to default format
|
// If specific image format is unsupported on this hardware, fallback to default format
|
||||||
Log.warn('Initial camera format initialization failed ($e), trying fallback format...');
|
Log.warn(
|
||||||
|
'Initial camera format initialization failed ($e), trying fallback format...',
|
||||||
|
);
|
||||||
await controller.dispose();
|
await controller.dispose();
|
||||||
controller = CameraController(
|
controller = CameraController(
|
||||||
AppEnvironment.cameras[cameraId],
|
AppEnvironment.cameras[cameraId],
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ class HomeViewState extends State<HomeView> with WidgetsBindingObserver {
|
||||||
StreamSubscription<int>? _homeViewPageIndexSub;
|
StreamSubscription<int>? _homeViewPageIndexSub;
|
||||||
StreamSubscription<NotificationResponse>? _selectNotificationSub;
|
StreamSubscription<NotificationResponse>? _selectNotificationSub;
|
||||||
|
|
||||||
|
static Uri? pendingSharedLink;
|
||||||
static final streamHomeViewPageIndex = StreamController<int>.broadcast();
|
static final streamHomeViewPageIndex = StreamController<int>.broadcast();
|
||||||
static final streamSharedLink = StreamController<Uri>.broadcast();
|
static final streamSharedLink = StreamController<Uri>.broadcast();
|
||||||
|
|
||||||
|
|
@ -56,7 +57,10 @@ class HomeViewState extends State<HomeView> with WidgetsBindingObserver {
|
||||||
super.initState();
|
super.initState();
|
||||||
WidgetsBinding.instance.addObserver(this);
|
WidgetsBinding.instance.addObserver(this);
|
||||||
var initialPage = widget.initialPage;
|
var initialPage = widget.initialPage;
|
||||||
if (initialPage == 1 && !userService.currentUser.startWithCameraOpen) {
|
if (HomeViewState.pendingSharedLink != null) {
|
||||||
|
initialPage = 1;
|
||||||
|
} else if (initialPage == 1 &&
|
||||||
|
!userService.currentUser.startWithCameraOpen) {
|
||||||
initialPage = 0;
|
initialPage = 0;
|
||||||
}
|
}
|
||||||
_activePageIdx = initialPage;
|
_activePageIdx = initialPage;
|
||||||
|
|
@ -100,6 +104,22 @@ class HomeViewState extends State<HomeView> with WidgetsBindingObserver {
|
||||||
streamHomeViewPageIndex.add(0);
|
streamHomeViewPageIndex.add(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_sharedLinkSub = streamSharedLink.stream.listen((uri) {
|
||||||
|
HomeViewState.pendingSharedLink = null;
|
||||||
|
_mainCameraController.setSharedLinkForPreview(uri);
|
||||||
|
Permission.camera.isGranted.then((hasPermission) {
|
||||||
|
if (hasPermission && mounted) {
|
||||||
|
unawaited(_mainCameraController.selectCamera(0, true));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (HomeViewState.pendingSharedLink != null) {
|
||||||
|
final link = HomeViewState.pendingSharedLink!;
|
||||||
|
HomeViewState.pendingSharedLink = null;
|
||||||
|
_mainCameraController.setSharedLinkForPreview(link);
|
||||||
|
}
|
||||||
|
|
||||||
if (initialPage == 1) {
|
if (initialPage == 1) {
|
||||||
Permission.camera.isGranted.then((hasPermission) {
|
Permission.camera.isGranted.then((hasPermission) {
|
||||||
if (hasPermission && mounted) {
|
if (hasPermission && mounted) {
|
||||||
|
|
@ -110,14 +130,11 @@ class HomeViewState extends State<HomeView> with WidgetsBindingObserver {
|
||||||
|
|
||||||
unawaited(_initAsync());
|
unawaited(_initAsync());
|
||||||
|
|
||||||
_sharedLinkSub = streamSharedLink.stream.listen(
|
|
||||||
_mainCameraController.setSharedLinkForPreview,
|
|
||||||
);
|
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
if (widget.initialPage == 1 &&
|
if (_mainCameraController.sharedLinkForPreview == null &&
|
||||||
!userService.currentUser.startWithCameraOpen ||
|
((widget.initialPage == 1 &&
|
||||||
widget.initialPage == 0) {
|
!userService.currentUser.startWithCameraOpen) ||
|
||||||
|
widget.initialPage == 0)) {
|
||||||
streamHomeViewPageIndex.add(0);
|
streamHomeViewPageIndex.add(0);
|
||||||
}
|
}
|
||||||
Future.delayed(const Duration(seconds: 1), () {
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue