keyboard focus + app_info

This commit is contained in:
agra
2026-04-21 16:54:56 +03:00
parent fb40549cce
commit b8d77e0a3a
8 changed files with 449 additions and 1 deletions

5
lib/src/app_info.dart Normal file
View File

@@ -0,0 +1,5 @@
class AppInfo {
final String version;
final int buildNumber;
const AppInfo({required this.version, required this.buildNumber});
}

View File

@@ -4,6 +4,7 @@ import 'dart:math' as math;
import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
DynamicLibrary? _initLib() {
if (Platform.isIOS) return DynamicLibrary.process();
@@ -141,6 +142,9 @@ double _inverseLerp(List<double> samples, double value) {
/// ```
class UxKeyboard with ChangeNotifier {
UxKeyboard._() {
if (Platform.isAndroid) {
_channel.setMethodCallHandler(_onMethodCall);
}
if (_lib == null) return;
SchedulerBinding.instance.addPersistentFrameCallback(_onFrame);
}
@@ -148,6 +152,26 @@ class UxKeyboard with ChangeNotifier {
/// The singleton instance.
static final UxKeyboard instance = UxKeyboard._();
static const _channel = MethodChannel('ux/keyboard');
/// Increments each time the native window gains input focus — the signal
/// Android needs before the IME can be raised. Listen for changes when you
/// want to re-trigger a pending focus request at cold start (e.g. a
/// `TextField(autofocus: true)` whose initial `TextInput.show` was dropped
/// because the window wasn't yet focused).
///
/// The value itself is a monotonically-increasing counter — only useful as a
/// change signal, not as an absolute state.
final windowFocusCounter = ValueNotifier<int>(0);
Future<dynamic> _onMethodCall(MethodCall call) async {
switch (call.method) {
case 'onWindowFocused':
windowFocusCounter.value++;
break;
}
}
double _height = 0;
/// The current keyboard height in logical pixels.