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

35
lib/builder.dart Normal file
View File

@@ -0,0 +1,35 @@
import 'dart:async';
import 'package:build/build.dart';
Builder appInfoBuilder(BuilderOptions options) => _AppInfoBuilder();
class _AppInfoBuilder implements Builder {
@override
Map<String, List<String>> get buildExtensions => const {
r'$package$': ['lib/app_info.g.dart'],
};
@override
Future<void> build(BuildStep buildStep) async {
final pkg = buildStep.inputId.package;
final raw = await buildStep.readAsString(AssetId(pkg, 'pubspec.yaml'));
final match =
RegExp(r'^version:\s*([^\s#]+)', multiLine: true).firstMatch(raw);
final combined = match?.group(1) ?? '0.0.0+0';
final plus = combined.indexOf('+');
final version = plus < 0 ? combined : combined.substring(0, plus);
final buildNumber =
plus < 0 ? 0 : int.tryParse(combined.substring(plus + 1)) ?? 0;
await buildStep.writeAsString(
AssetId(pkg, 'lib/app_info.g.dart'),
'''
// GENERATED by build_runner from pubspec.yaml — do not edit.
import 'package:ux/ux.dart';
const kAppInfo = AppInfo(version: '$version', buildNumber: $buildNumber);
''',
);
}
}

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.

View File

@@ -4,6 +4,7 @@
/// [BendBox] for curved layout painting, and bezier curve utilities.
library;
export 'src/app_info.dart';
export 'src/bend_box.dart';
export 'src/json_extension.dart';
export 'src/bezier.dart';