Flutter:键盘自动关闭`AccordionSection`

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

描述:

我在使用 Accordion 包版本 2.6.0 时遇到了 Flutter 应用程序的问题。我在 AccordionSection 中有一个 TextField,当我尝试在 TextField 中输入文本时,键盘会打开并立即关闭 AccordionSection。

代码片段:

个人资料视图

class MyView extends StatelessWidget {                      
  @override
  Widget build(BuildContext context) {
    Accordion(
      scaleWhenAnimating: false,
      openAndCloseAnimation: true,
      sectionOpeningHapticFeedback: SectionHapticFeedback.heavy,
      sectionClosingHapticFeedback: SectionHapticFeedback.light,
      children: [
        AccordionSection(
          headerBackgroundColor: AppTheme.colors.lightbeige,
          contentBorderColor: AppTheme.colors.lightbeige,
          contentBackgroundColor: AppTheme.colors.lightbeige,
          rightIcon: Icon(Icons.expand_more,
              color:
                  AppTheme.colors.getColorForUserType(isStudent)),
          header: Padding(
            padding:
                const EdgeInsets.only(left: 20, top: 8, bottom: 8),
            child: Text(
              "Supprimer mon profil",
              style: AppTheme.text.labelStyle.copyWith(),
            ),
          ),
          content: CustomSection(
            isStudent: isStudent,
          ),
        ),
      ],
    ),
  }
}

import 'package:flutter/material.dart';
import 'package:frontend/theme/theme.dart';

class CustomSection extends StatefulWidget {
  final bool isStudent;
  final FocusNode _focusNode = FocusNode();

  DeleteProfileSection({super.key, required this.isStudent});

  @override
  State<DeleteProfileSection> createState() => _DeleteProfileSectionState();
}

class _CustomSectionState extends State<CustomSection> {
  final TextEditingController controller = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Container(
        width: double.infinity,
        padding: const EdgeInsets.all(10),
        child: Column(
          children: [
            Text(
                style: AppTheme.text.latoDarkGray14fw400,
                "Tu es sûr(e) de vouloir supprimer ton compte ? Cette action est irréversible, elle te déconnectera et toutes tes données seront supprimées."),
            const SizedBox(height: 20),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  'Mot de passe *',
                  style: AppTheme.text.labelStyle,
                ),
                const SizedBox(height: 10),
                TextField(
                  autocorrect: false,
                  autofillHints: const [AutofillHints.password],
                  controller: controller,
                  focusNode: widget._focusNode,
                  obscureText: true,
                  decoration: InputDecoration(
                    hintText: 'Mot de passe',
                    hintStyle: AppTheme.text.hintStyle,
                    filled: true,
                    fillColor: AppTheme.colors.white,
                    constraints: const BoxConstraints(
                        minHeight: 40, minWidth: 150, maxWidth: 300),
                  ),
                ),
              ],
            ),
            const SizedBox(height: 20),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                TextButton(
                    onPressed: () {},
                    child: Text('Annuler',
                        style: AppTheme.text.latoWhiteFs14Fw400.copyWith(
                            color: AppTheme.colors
                                .getColorForUserType(widget.isStudent)))),
                ElevatedButton(
                  style: ElevatedButton.styleFrom(
                    backgroundColor:
                        AppTheme.colors.getColorForUserType(widget.isStudent),
                    minimumSize: const Size(150, 40),
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10),
                    ),
                  ),
                  onPressed: () {},
                  child: Text(
                    'Supprimer mon compte',
                    style: AppTheme.text.latoWhiteFs14Fw400,
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

环境:

颤振版本:3.16.2 手风琴包版本:2.6.0

预期行为:

我希望当我在 TextField 中输入文本时 AccordionSection 保持打开状态。键盘不应触发该部分的关闭。

实际行为:

打开键盘时 AccordionSection 会关闭,破坏用户体验。

附加信息:

我尝试探索 Accordion 包的文档,但找不到有关此问题的任何具体信息。任何有关如何防止 AccordionSection 在键盘打开时关闭的指导或建议将不胜感激。

谢谢您的帮助!

flutter dart keyboard textfield accordion
1个回答
0
投票

您找到解决方案了吗?面临同样的问题

© www.soinside.com 2019 - 2024. All rights reserved.