键盘打开时在 ios 设备中显示小吃栏

问题描述 投票:0回答:1

enter image description here当键盘关闭时,我的小吃栏显示完美,但当它打开时,它在 ios 中无法正确显示


Future<void> _login() async {
  if (!_formKey.currentState!.validate()) return;

  final request = LoginRequest(
    countryCode: "+91",
    phoneNumber: _phoneNumberController.text,
  );

  try {
    final response = await http.post(
      Uri.parse('xxxxxx'),
      headers: {'Content-Type': 'application/json'},
      body: jsonEncode(request.toJson()),
    );

    print('Response status: ${response.statusCode}');
    print('Response body: ${response.body}');

    if (response.statusCode == 200 || response.statusCode == 201) {
      final data = jsonDecode(response.body);
      final loginResponse = LoginResponse.fromJson(data);
        await _saveUserData('Your Name', _phoneNumberController.text); 

      if (loginResponse.message != '' && loginResponse.message.isNotEmpty) {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(content: Text(loginResponse.message)),
        );

        Navigator.of(context).push(
          MaterialPageRoute(
            builder: (context) =>  OtpScreen(
              phoneNumber: _phoneNumberController.text,
              countryCode: '+91',
            ),
          ),
        );
      } else {
        ScaffoldMessenger.of(context).showSnackBar(
        const  SnackBar(content: Text('Login successful, but no message provided')),
        );
      }
    } else {
      final errorData = jsonDecode(response.body);
      final errorMessage = errorData['message'] ?? 'Failed to sign up';
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text(errorMessage)),
      );
    }
  } catch (e) {
    print('Error: $e');
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(content: Text('An error occurred: $e')),
    );
  }
}

我希望当键盘打开时,小吃栏也会正确显示,我已经看到了许多适用于 Android 的解决方案,但在 ios 中没有看到

ios flutter keyboard snackbar
1个回答
0
投票

请添加此

SnackBarBehavior.floating
,如下所示:

  SnackBar(
    content: Text(loginResponse.message),
    behavior: SnackBarBehavior.floating, // Make the snackbar float above other content
  ),
© www.soinside.com 2019 - 2024. All rights reserved.