如果主体很小,如何防止NestedScrollView滚动?

时间:2020-04-09 16:59:27

标签: flutter

NestedScrollView较小时,如何防止headerSliverBuilder滚动body

在下面的示例中,如果SliverAppBar不需要滚动,我想阻止body滚动,因为它很小,即在该示例中,视图根本不滚动,但确实如此。

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: NestedScrollView(
      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
        return <Widget>[
          SliverAppBar(
            title: Text('Demo'),
            expandedHeight: 300,
          )
        ];
      },
      body: CustomScrollView(
        slivers: <Widget>[
          SliverToBoxAdapter(
            child: Container(color: Colors.red, height: 100),
          ),
          SliverToBoxAdapter(
            child: Container(color: Colors.amber, height: 100),
          ),
        ],
      ),
    ));
  }
}

可以通过将SliverAppBar移到CustomScrollView而不使用NestedScrollView来解决问题。不过,这并不是我的解决方案,因为https://github.com/flutter/flutter/issues/12033基本上要求我使用NestedScrollView

0 个答案:

没有答案