keyboard focus + app_info
This commit is contained in:
35
lib/builder.dart
Normal file
35
lib/builder.dart
Normal 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
5
lib/src/app_info.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
class AppInfo {
|
||||
final String version;
|
||||
final int buildNumber;
|
||||
const AppInfo({required this.version, required this.buildNumber});
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user