Нижний лист Flutter скрывается за клавиатурой - PullRequest
0 голосов
/ 08 мая 2020

У меня есть 2 входа на нижнем листе, но проблема в том, что когда я открываю клавиатуру, она покрывает весь нижний лист, а фоновая страница перемещается вверх, а не на нижний лист.

Вот мой код

class _addQuestionState extends State<addQuestion> {


  void _submitData(){
    Navigator.of(context).pop();
  }


  @override
  Widget build(BuildContext context) {
    double stackHeight = (MediaQuery.of(context).size.height);
    return Container(
      color: new Color.fromRGBO(255, 0, 0, 0.5),
      child: Container(
        height: stackHeight * 0.4,
        decoration: BoxDecoration(
            color: Color(0xff404040),
            borderRadius: BorderRadius.only(topLeft: Radius.circular(15.0), topRight: Radius.circular(15.0))
        ),
        child: Center(
          child: SingleChildScrollView(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Container(

                  padding: EdgeInsets.only(top: 10, left: 10, right:10,
                    bottom: MediaQuery.of(context).viewInsets.bottom + 10 ,
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      TextField(
                        maxLength: 56,
                        style: TextStyle(
                          color: Colors.white,
                        ),
                        textAlign: TextAlign.center,
                        decoration: InputDecoration(
                          counterText: '',
                          labelText: 'Would Question',
                          labelStyle: TextStyle(
                              color: Colors.blue
                          ),
                          enabledBorder: UnderlineInputBorder(
                            borderSide: BorderSide(color: Colors.blue),
                          ),
                          focusedBorder: UnderlineInputBorder(
                            borderSide: BorderSide(color: Colors.blue),
                          ),
                        ),
                        onSubmitted: (_) => _submitData(),
                      ),
                      TextField(
                        maxLength: 56,
                        style: TextStyle(
                          color: Colors.white,
                        ),
                        textAlign: TextAlign.center,
                        decoration: InputDecoration(
                          counterText: '',
                          labelText: 'Rather Question',
                          labelStyle: TextStyle(
                              color: Colors.red
                          ),
                          enabledBorder: UnderlineInputBorder(
                            borderSide: BorderSide(color: Colors.red),
                          ),
                          focusedBorder: UnderlineInputBorder(
                            borderSide: BorderSide(color: Colors.red),
                          ),
                        ),
                        onSubmitted: (_) => _submitData(),
                      ),
                      SizedBox(height: stackHeight * 0.04,),
                      RaisedButton(onPressed: () {
                        _submitData();

                      }, child: Text('Add Question', style: TextStyle(
                          color: Colors.white
                      ),),color: Theme.of(context).primaryColor,
                      ),

                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

И я называю это как

void _startAddnewTransaction(BuildContext ctx){
  showModalBottomSheet(context: ctx, builder: (_) {
    return addQuestion();
  });
}

Вот изображение enter image description here

enter image description here

Как вы можете видеть на изображении 2, когда клавиатура открыта, фон движется вверх, но нижний лист не движется

1 Ответ

0 голосов
/ 08 мая 2020

используйте SingleChildScrollView в root дереве виджетов в методе «сборки», например:

@override
  Widget build(BuildContext context) {
    double stackHeight = (MediaQuery.of(context).size.height);
    return SingleChildScrollView(
           child: Container(child:....));
}
...