Skip to content

Commit

Permalink
Enable Keyboard Autofill for recent Android versions
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyrat committed Nov 9, 2023
1 parent b023b27 commit 826f3fe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
<meta-data
android:name="com.keevault.flutter_autofill_service.match_header_drawable_name"
android:value="ic_v_light_key_24dp" />
<meta-data
android:name="com.keevault.flutter_autofill_service.pinned_drawable_name"
android:value="ic_v_light_key_24dp" />

<service
android:name="com.keevault.flutter_autofill_service.FlutterAutofillService"
Expand Down
36 changes: 36 additions & 0 deletions lib/widgets/settings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:async';
import 'dart:io';

import 'package:biometric_storage/biometric_storage.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -444,10 +446,15 @@ class _AutofillStatusWidgetState extends State<AutofillStatusWidget> {
buildSignature: 'Unknown',
);

// ignore: unused_field
BaseDeviceInfo? _deviceInfo;
AndroidDeviceInfo? _androidDeviceInfo;

@override
void initState() {
super.initState();
unawaited(_initPackageInfo());
unawaited(_initDeviceInfo());
}

Future<void> _initPackageInfo() async {
Expand All @@ -459,6 +466,18 @@ class _AutofillStatusWidgetState extends State<AutofillStatusWidget> {
}
}

Future<void> _initDeviceInfo() async {
final deviceInfoPlugin = DeviceInfoPlugin();
final deviceInfo = await deviceInfoPlugin.deviceInfo;
final androidInfo = Platform.isAndroid ? await deviceInfoPlugin.androidInfo : null;
if (mounted) {
setState(() {
_deviceInfo = deviceInfo;
_androidDeviceInfo = androidInfo;
});
}
}

@override
Widget build(BuildContext context) {
final str = S.of(context);
Expand Down Expand Up @@ -513,6 +532,23 @@ class _AutofillStatusWidgetState extends State<AutofillStatusWidget> {
},
),
),
Visibility(
visible: widget.isEnabled && KeeVaultPlatform.isAndroid && (_androidDeviceInfo?.version.sdkInt ?? 0) >= 31,
child: SwitchSettingsTile(
settingKey: 'autofillServiceEnableIMEIntegration',
title: 'Show in keyboard',
subtitle: 'experimental feature',
defaultValue: true,
onChange: (value) async {
// We assume the autofill preference's SharedPreferences feature
// is in sync to begin with and always specify what the user has
// requested from our own preference so in the worst case, the
// user will have to toggle the switch a couple of times to
// resync and fix any broken behaviour.
await BlocProvider.of<AutofillCubit>(context).setIMEIntegrationPreference(value);
},
),
),
]),
),
Divider(
Expand Down

0 comments on commit 826f3fe

Please sign in to comment.