gpt4 book ai didi

flutter - D/输入连接适配器(3218) : The input method toggled cursor monitoring on

转载 作者:行者123 更新时间:2023-12-03 08:06:59 42 4
gpt4 key购买 nike

这是我在 auth_screen.dart 文件的卡片小部件内使用的表单的一部分:

child: Obx(() => Form(
key: _formKey,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
TextFormField(
decoration: const InputDecoration(labelText: 'E-Mail'),
keyboardType: TextInputType.emailAddress,
validator: (value) {
if (value!.isEmpty || !value.contains('@')) {
return 'Invalid email!';
}
},
onSaved: (value) {
_authData['email'] = value as String;
},
),
TextFormField(
decoration: const InputDecoration(labelText: 'Password'),
obscureText: true,
controller: _passwordController,
validator: (value) {
if (value!.isEmpty || value.length < 5) {
return 'Password is too short!';
}
},
onSaved: (value) {
_authData['password'] = value as String;
},
),

有两个 TextFormField 用于通过电子邮件发送密码。

还有相关的auth_controller.dart文件如下:

enum AuthMode { Signup, Login }

class AuthController extends GetxController
with GetSingleTickerProviderStateMixin {
static AuthController instance = Get.find();
Rx<dynamic>? authMode = AuthMode.Login.obs;
RxBool? isLoading = false.obs;
String? _token;
DateTime? _expiryDate;
String? _userId;
Timer? _authTimer;
final _isAuth = false.obs;

AnimationController? controller;
Animation<Offset>? slideAnimation;
Animation<double>? opacityAnimation;
late TextEditingController passwordController;
final key = GlobalKey<FormState>();

@override
void onInit() {
super.onInit();
tryAutoLogin();
controller = AnimationController(
vsync: this,
duration: const Duration(
milliseconds: 300,
),
);
slideAnimation = Tween<Offset>(
begin: const Offset(0, -1.5),
end: const Offset(0, 0),
).animate(
CurvedAnimation(
parent: controller as Animation<double>,
curve: Curves.fastOutSlowIn,
),
);
opacityAnimation = Tween(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: controller as Animation<double>,
curve: Curves.easeIn,
),
);
// _heightAnimation.addListener(() => setState(() {}));

passwordController = TextEditingController();
}

@override
void onClose() {
super.onClose();
passwordController.dispose();
}

bool get isAuth {
_isAuth.value = token != null;
return _isAuth.value;
}

String? get token {
if (_expiryDate != null &&
_expiryDate!.isAfter(DateTime.now()) &&
_token != null) {
return _token;
}
return null;
}

String? get userId {
return _userId;
}

Future<void> _authenticate(
String email, String password, String urlSegment) async {
// print('app is here!!!5555');
// const host = "localhost";
final host = UniversalPlatform.isAndroid ? '10.0.2.2' : '127.0.0.1';
final url = Uri.parse('http://$host:8000/api/$urlSegment');

try {
final http.Response response = await http.post(
url,
headers: {"Content-Type": "application/json"},
body: json.encode(
{
'email': email,
'password': password,

//'returnSecureToken': true,
},
),
);
// print('this is responsde ' );
// print(response);

final responseData = json.decode(response.body);
print(responseData);

if (responseData['error'] != null) {
throw HttpException(responseData['error']['message']);
} else {
_token = responseData['idToken'];
_userId = responseData['id'];
_expiryDate = DateTime.now().add(
Duration(
milliseconds: responseData['expiresIn'],
),
);
}
_autoLogout();
// update();
final prefs = await SharedPreferences.getInstance();
final userData = json.encode(
{
'token': _token,
'userId': _userId,
'expiryDate': _expiryDate!.toIso8601String(),
},
);
prefs.setString('userData', userData);
isLoading?.value = false;

// print(prefs.getString('userData'));
Get.toNamed(rootRoute);
} catch (error) {
throw error;
}
}

Future<void> signup(String email, String password) async {
return _authenticate(email, password, 'signup');
}

Future<void> login(String email, String password) async {
return _authenticate(email, password, 'sessions');
}

Future<bool> tryAutoLogin() async {
final prefs = await SharedPreferences.getInstance();
if (!prefs.containsKey('userData')) {
return false;
}
final Map<String, Object> extractedUserData = Map<String, Object>.from(
json.decode(prefs.getString('userData') as String));
final expiryDate =
DateTime.parse(extractedUserData['expiryDate'] as String);

if (expiryDate.isBefore(DateTime.now())) {
return false;
}
_token = extractedUserData['token'] as String;
_userId = extractedUserData['userId'] as String;
_expiryDate = expiryDate;
_isAuth.value = true;
_autoLogout();
return true;
}

Future<void> logout() async {
_token = null;
_userId = null;
_expiryDate = null;
if (_authTimer != null) {
_authTimer!.cancel();
_authTimer = null;
}
// update();
final prefs = await SharedPreferences.getInstance();
// prefs.remove('userData');
prefs.clear();
_isAuth.value = false;
}

void _autoLogout() {
if (_authTimer != null) {
_authTimer!.cancel();
}
final timeToExpiry = _expiryDate!.difference(DateTime.now()).inSeconds;
_authTimer = Timer(Duration(seconds: timeToExpiry), logout);
}
}

当我启动应用程序时,它似乎运行没有错误,但是当我单击 TextFormField 输入电子邮件或密码时,Android 模拟器上的虚拟键盘会立即打开和关闭,并且不允许我输入任何内容。它还在调试控制台中显示以下消息:

D/InputConnectionAdaptor( 3218): The input method toggled cursormonitoring on

最佳答案

经过这么多努力,我发现请使用 StatefullWidget 而不是 StateLessWidget 。希望对您有帮助!

关于flutter - D/输入连接适配器(3218) : The input method toggled cursor monitoring on,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71991917/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com