我想在ListView
内NestedScrollView
让SliverAppBar
崩溃。但是,如果我向ListView
添加控制器,它将停止工作(AppBar
不会崩溃)。这是一个示例,其中左ListView
不会影响SliverAppBar
,但右ListView
会影响import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
ScrollController scrollController = new ScrollController();
List<String> entries = ["a", "b", "c", "d", "e", "a", "b", "c", "d", "e"];
@override
Widget build(BuildContext context) {
return new DefaultTabController(
length: 2,
child: new Scaffold(
body: new NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
new SliverAppBar(
title: new Text("My app"),
pinned: true,
expandedHeight: 150.0,
floating: true,
forceElevated: innerBoxIsScrolled,
bottom: new TabBar(
tabs: <Tab>[
new Tab(text: "FIRST"),
new Tab(text: "SECOND"),
],
)),
];
},
body: new TabBarView(
children: <Widget>[
new ListView.builder(
itemCount: entries.length,
controller: scrollController,
itemExtent: 60.0,
itemBuilder: (buildContext, index) {
return new Text(entries[index]);
},
),
new ListView.builder(
itemCount: entries.length,
itemExtent: 60.0,
itemBuilder: (buildContext, index) {
return new Text(entries[index]);
},
),
],
),
),
),
);
}
}
。
ListView
您是否知道是否可以将控制器附加到NestedScrollView
并仍然通知<SOAP-ENV:Body>
<log-entry serial="abcde" domain="abc">
<date>Tue Oct 17 2017</date>
<time utc="abcde">14:14:30</time>
<type>all</type>
<class>ccccc</class>
<object>Web_Token</object>
<level num="5">notice</level>
<transaction>xxxxx</transaction>
<global-transaction-id>xxxxx</global-transaction-id>
<client>X.X.X.X</client>
<message>
<base64>**encodeddata**</base64>
</message>
</log-entry>
</SOAP-ENV:Body>
i need output
<SOAP-ENV:Body>
<log-entry serial="abcde" domain="abc">
<date>Tue Oct 17 2017</date>
<time utc="abcde">14:14:30</time>
<type>all</type>
<class>ccccc</class>
<object>Web_Token</object>
<level num="5">notice</level>
<transaction>xxxxx</transaction>
<global-transaction-id>xxxxx</global-transaction-id>
<client>X.X.X.X</client>
<message>
<base64>**decodeddata**</base64>
</message>
</log-entry>
</SOAP-ENV:Body>
?
答案 0 :(得分:7)
如果您正在使用NestedScrollView
,则您选择让它管理每个孩子Scrollable
的滚动位置,就好像它们都是统一的可滚动一样。没有办法驱动个体Scrollable
孩子与控制者的位置;这样做会很有挑战性,因为它可能会使NestedScrollView
处于混乱状态。但是,你并非完全没有运气:
NestedScrollView
。Scrollable
包裹在NotificationListener
中以监听{{3 }}。Scrollable
&#34;重置&#34;在初始滚动位置为零时,您可以更改其key
以消除其状态。