Flutter - SingleChildScrollView interferes with columns

I created a screen that works well with columns, but I needed to scroll due to the keyboard.

When you insert an attribute SingleChildScrollViewor ListView MainAxisAlignment.spaceBetween, it no longer works.

Was there a solution for this?

Gif without a SingleChildScrollViewscreen does not roll, but FloatingActionButtonis at the bottom of the screen

enter image description here

Gif with a SingleChildScrollViewroll of screen and it is FloatingActionButtonnot at the bottom of the screen

enter image description here

import 'package:flutter/material.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(      
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(backgroundColor: new Color(0xFF26C6DA)),        
      body: new SingleChildScrollView(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              new Container(
                child: new Column(
                  children: <Widget>[
                    new TextField(
                      decoration: const InputDecoration(
                        labelText: "Description",
                      ),
                      style: Theme.of(context).textTheme.title,
                      ),
                    new TextField(
                      decoration: const InputDecoration(
                        labelText: "Description",
                      ),
                      style: Theme.of(context).textTheme.title,
                    ),
                    new TextField(
                      decoration: const InputDecoration(
                        labelText: "Description",
                      ),
                      style: Theme.of(context).textTheme.title,
                    ),
                  ],
                )
              ),
              new Container(
                margin: new EdgeInsets.only(bottom: 16.0),
                child: new FloatingActionButton(
                  backgroundColor: new Color(0xFFE57373),
                  child: new Icon(Icons.check),
                  onPressed: (){}
                ),                    
              )
            ],
        ),
      )            
    );
  }
}
0
source share
2 answers

FloatingActionButton , . FloatingActionButton , . . , , RaisedButton FlatButton. RaisedButton , , AppBar, .

RaisedButton FlatButton, , . MainAxisAlignment.spaceBetween Padding RaisedButton, TextField. , , , ​​ .

+3

.

MainAxisAlignment.spaceBetween .

import 'package:flutter/material.dart';
import 'dart:ui' as ui;

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(      
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    final ui.Size logicalSize = MediaQuery.of(context).size;
    final double _height = logicalSize.height;
    return new Scaffold(
      appBar: new AppBar(backgroundColor: new Color(0xFF26C6DA)),        
      body: new SingleChildScrollView(
        child: new Column(
          //mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              new Container(
                height: 300.0,
                child: new Column(
                  children: <Widget>[
                    new TextField(
                      decoration: const InputDecoration(
                        labelText: "Description",
                      ),
                      style: Theme.of(context).textTheme.title,
                    ),
                    new TextField(
                      decoration: const InputDecoration(
                        labelText: "Description",
                      ),
                      style: Theme.of(context).textTheme.title,
                    ),
                    new TextField(
                      decoration: const InputDecoration(
                        labelText: "Description",
                      ),
                      style: Theme.of(context).textTheme.title,
                    ),
                  ],
                )
              ),
              new Container(
                padding: new EdgeInsets.only(top: (_height - 450.0)),
                margin: new EdgeInsets.only(bottom: 16.0),
                child: new FloatingActionButton(
                  backgroundColor: new Color(0xFFE57373),
                  child: new Icon(Icons.check),
                  onPressed: (){}
                ),
              )
            ],
        ),
      )
    );
  }
}
0

Source: https://habr.com/ru/post/1684782/


All Articles