flutter 如何调整或重新定位或滚动小部件 Package 下的堆栈与定位小部件,而使用键盘的文本字段?

h4cxqtbf  于 2022-12-30  发布在  Flutter
关注(0)|答案(1)|浏览(110)

下面是我的候选人_个人资料_屏幕. dart。
键盘打开时,我的文本字段被隐藏!
希望很快就能找到解决办法。

import 'package:flutter/material.dart';
import 'package:job_ifaserp/candidate_module/resouces/candidate_header.dart';
import 'package:job_ifaserp/commons/custom_wdgets.dart';
import 'models/candidate_master.dart';

class CandidateProfileScreen extends StatelessWidget {
  final String? emailID;
  final CandidateMaster? canMast;
  CandidateProfileScreen({Key? key, this.canMast, this.emailID})
      : super(key: key);
  TextEditingController txtCandidateName = TextEditingController();
  TextEditingController txtCandidateEmail = TextEditingController();
  TextEditingController txtCandidateContact = TextEditingController();
  TextEditingController txtCandidateSkill = TextEditingController();
  TextEditingController txtCandidateAbout = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: true,
      appBar: AppBar(title: const Text('Jobseeker Profile'),),
      body: Stack(
        children: [
          CandidateHeader(canMast: canMast, emailID: emailID),
          Positioned(
              top: 150,
              left: 40,
              child: Container(
                width: 300,
                height: 200,
                child: const Text(
                  'Update Profile',
                  style: TextStyle(
                      fontSize: 25, fontWeight: FontWeight.bold),
                ),
              )),
          Positioned(
              top: 190,
              left: 40,
              child: Container(
                  width: 350,
                  height: 75,
                  child: RoundedInput(icon: Icons.person,
                      hint: canMast!.can_name.toString(),
                      txtController: txtCandidateName,
                      onChangeText: (_) {})
              )),
          Positioned(
              top: 250,
              left: 40,
              child: Container(
                  width: 350,
                  height: 75,
                  child: RoundedInput(icon: Icons.email,
                      hint: canMast!.can_email.toString(),
                      txtController: txtCandidateEmail,
                      onChangeText: (_) {})
              )),
          Positioned(
              top: 310,
              left: 40,
              child: Container(
                  width: 350,
                  height: 75,
                  child: RoundedInput(icon: Icons.mobile_friendly,
                      hint: canMast!.can_mobn.toString(),
                      txtController: txtCandidateContact,
                      onChangeText: (_) {})
              )),
          Positioned(
              top: 370,
              left: 40,
              //bottom: 310,
              child: Container(
                  width: 350,
                  height: 75,
                  child: RoundedInput(icon: Icons.person_add,
                      hint: 'Your skill',
                      txtController: txtCandidateSkill,
                      onChangeText: (_) {})
              )),
          Positioned(
              top: 430,
              left: 40,
              // bottom: 175,
              child: Container(
                  width: 350,
                  height: 150,
                  child: RoundedInput(icon: Icons.tag,
                      hint: 'About me / Profile tag',
                      txtController: txtCandidateAbout,
                      onChangeText: (_) {})
              )),
          Positioned(
              top: 600,
              left: 80,
              child: Container(
                  width: 250,
                  height: 60,
                  child: RoundedButton(title: 'Update', onPressRoundButton: () {})
              )),
          Positioned(
              top: 670,
              left: 80,
              child: Container(
                  width: 250,
                  height: 60,
                  child: RoundedButton(title: 'Back', onPressRoundButton: () {
                    Navigator.pop(context);
                  })
              )),
        ],
      ),
    );
  }
}

candidate_profile_screen.dart](https://i.stack.imgur.com/oWg0q.jpg
我试过SingleChildScrollView,但没有效果。我也试过用AnimatedContainer Package ,但找不到方法。
我希望当键盘发生在屏幕上,而编辑文本字段,然后小部件不应该隐藏在键盘下。

esyap4oy

esyap4oy1#

我得到的答案如下。
我使用height: MediaQuery.of(context).size.height属性将AnimatedContainer小部件与AnimatedContainer Package 在一起。
然后用SingleChildScrollView Package AnimatedContainer
同时将resizeToAvoidBottomInset: true放在Scaffold下面
我的新代码如下

import 'package:flutter/material.dart';
import 'package:job_ifaserp/candidate_module/resouces/candidate_header.dart';
import 'package:job_ifaserp/commons/custom_wdgets.dart';
import 'models/candidate_master.dart';

class CandidateProfileScreen extends StatelessWidget {
  final String? emailID;
  final CandidateMaster? canMast;
  CandidateProfileScreen({Key? key, this.canMast, this.emailID})
      : super(key: key);
  TextEditingController txtCandidateName = TextEditingController();
  TextEditingController txtCandidateEmail = TextEditingController();
  TextEditingController txtCandidateContact = TextEditingController();
  TextEditingController txtCandidateSkill = TextEditingController();
  TextEditingController txtCandidateAbout = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: true,
      appBar: AppBar(title: const Text('Jobseeker Profile'),),
      body: SingleChildScrollView(
        child: AnimatedContainer(
          duration: const Duration(milliseconds: 200),
          height: MediaQuery.of(context).size.height,
          child: Stack(
            clipBehavior: Clip.none,
            children: [
              CandidateHeader(canMast: canMast, emailID: emailID),
              Positioned(
                  top: 150,
                  left: 40,

                  child: Container(
                    width: 300,
                    height: 200,
                    child: const Text(
                      'Update Profile',
                      style: TextStyle(
                          fontSize: 25, fontWeight: FontWeight.bold),
                    ),
                  )),
              Positioned(
                  top: 190,
                  left: 40,

                  child: Container(
                      width: 350,
                      height: 75,
                      child: RoundedInput(icon: Icons.person,
                          hint: canMast!.can_name.toString(),
                          txtController: txtCandidateName,
                          onChangeText: (_) {})
                  )),
              Positioned(
                  top: 250,
                  left: 40,

                  child: Container(
                      width: 350,
                      height: 75,

                      child: RoundedInput(icon: Icons.email,
                          hint: canMast!.can_email.toString(),
                          txtController: txtCandidateEmail,
                          onChangeText: (_) {})
                  )),
              Positioned(
                  top: 310,
                  left: 40,

                  child: Container(
                      width: 350,
                      height: 75,
                      child: RoundedInput(icon: Icons.mobile_friendly,
                          hint: canMast!.can_mobn.toString(),
                          txtController: txtCandidateContact,
                          onChangeText: (_) {})
                  )),
              Positioned(
                  top: 370,
                  left: 40,

                  child: Container(
                      width: 350,
                      height: 75,
                      child: RoundedInput(icon: Icons.person_add,
                          hint: 'Your skill',
                          txtController: txtCandidateSkill,
                          onChangeText: (_) {})
                  )),
              Positioned(
                  top: 430,
                  left: 40,
                  child: Container(
                      width: 350,
                      height: 150,
                      child: RoundedInput(icon: Icons.tag,
                          hint: 'About me / Profile tag',
                          txtController: txtCandidateAbout,
                          onChangeText: (_) {})
                  )),
              Positioned(
                  top: 600,
                  left: 80,
                  child: Container(
                      width: 250,
                      height: 60,
                      child: RoundedButton(title: 'Update', onPressRoundButton: () {})
                  )),
              Positioned(
                  top: 670,
                  left: 80,
                  child: Container(
                      width: 250,
                      height: 60,
                      child: RoundedButton(title: 'Back', onPressRoundButton: () {
                        Navigator.pop(context);
                      })
                  )),
            ],
          ),
        ),
      ),
    );
  }
}

希望也会为你工作。
谢谢。

相关问题