Flutter - SingleChildScrollView interfering in columns

前端 未结 2 1391
一生所求
一生所求 2021-01-17 10:47

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

When you insert the SingleChildScrollView or the

相关标签:
2条回答
  • 2021-01-17 10:55

    Follow the code below to register.

    MainAxisAlignment.spaceBetween has been replaced with dynamic padding, depending on screen size.

    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 讨论(0)
  • 2021-01-17 11:12

    I would recommend against using FloatingActionButton in the way you are doing here. FloatingActionButton should be used for actions that always need to always be on screen at all times. See the Material guidelines on button usage for suggestions on other button types that can be scrolled, like RaisedButton and FlatButton. You could use a RaisedButton here, but I think it would be better to make your screen a dialog and put the save action in the AppBar as I suggested in your other question.

    If you do decide to use a RaisedButton or FlatButton, keep in mind that scrollables don't normally change their item spacing based on the size of their container. Instead of using MainAxisAlignment.spaceBetween, you could put some Padding around your RaisedButton to separate it from the TextField elements. This will ensure that they are spaced the same distance apart regardless of rotation, screen size, and regardless of whether the keyboard is up.

    0 讨论(0)
提交回复
热议问题