如何在flutter中使没有可滚动的标题和可滚动的主体?

时间:2019-01-19 14:32:20

标签: flutter

我正在尝试构建一个没有可滚动标题和可滚动主体的项目。 SliverAppbar是第一个选择,但是如果我移动身体,则我会丢失标头。我也可以使用Slidabele Tile。 SliverPersistentHeader是我的第二选择,但我可以使用Slidabele Tile。我的问题如下图所示。 main.dart标头不得滚动,正文必须包含硬编码的可滑动磁贴。如何在flutter中使滚动标题和滚动体都没有?

enter image description here

1 个答案:

答案 0 :(得分:2)

您应该在脚手架内部使用appBar: AppBar(...。 因此MaterialApp-> Scaffold->(AppBar和listview)。

示例代码:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("This is the title"),
        ),
        body: ListView(
          children: <Widget>[
            Text("This is text 1"),
            Text("This is text 2"),
            Text("This is text 3"),
            Text("This is text 4"),
            Text("This is text 5"),
            Text("This is text 6"),
            Text("This is text 7"),
            Text("This is text 8"),
            Text("This is text 9"),
            Text("This is text 10"),
            Text("This is text 11"),
            Text("This is text 12"),
            Text("This is text 13"),
            Text("This is text 14"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
            Text("This is text 15"),
          ],
        ),
      ),
    );
  }
}
相关问题