[Android] Support opening search page with shared text. Close #261

This commit is contained in:
2025-03-18 16:19:32 +08:00
parent f5b3b36acb
commit 3f6b3152b2
7 changed files with 97 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import 'package:flutter/services.dart';
import 'package:venera/foundation/app.dart';
import 'package:venera/pages/aggregated_search_page.dart';
bool _isHandling = false;
/// Handle text share event.
/// App will navigate to [AggregatedSearchPage] with the shared text as keyword.
void handleTextShare() async {
if (_isHandling) return;
_isHandling = true;
var channel = EventChannel('venera/text_share');
await for (var event in channel.receiveBroadcastStream()) {
if (App.mainNavigatorKey == null) {
await Future.delayed(const Duration(milliseconds: 200));
}
if (event is String) {
App.rootContext.to(() => AggregatedSearchPage(keyword: event));
}
}
}