颤振SingleChildScrollView和列位置

时间:2020-03-24 11:25:01

标签: flutter dart

我有一个问题。

我的应用是 SingleChildScrollView -> column -> children: A,B(variable height),C

我期待

如果A,B,C没有溢出。
C位置在屏幕底部。

如果A,B,C溢出。
C位置是内容的尾巴。

但这是行不通的。

因为SingleChildScrollView,我不能使用弹性的,垫片等等。

该怎么办? enter image description here

1 个答案:

答案 0 :(得分:2)

作为选择

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(child: SomeWidget()),
      ),
    );
  }
}

class SomeWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: <Widget>[
        SliverToBoxAdapter(
          child: Container(
            height: 340,
            color: Colors.red[200],
          ),
        ),
        SliverToBoxAdapter(
          child: Container(
            height: 620,
            color: Colors.orange[200],
          ),
        ),
        SliverFillRemaining(
          hasScrollBody: false,
          child: Align(
            alignment: Alignment.bottomCenter,
            child: Container(
              height: 80,
              color: Colors.green[200],
            ),
          ),
        ),
      ],
    );
  }
}

enter image description here