You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import'package:flutter/material.dart';
import'package:scrollview_observer/scrollview_observer.dart';
import'custom_scrollview_demo_page.dart';
voidmain() {
runApp(constMyApp());
}
classMyAppextendsStatelessWidget {
constMyApp({Key? key}) :super(key: key);
// This widget is the root of your application.@overrideWidgetbuild(BuildContext context) {
returnMaterialApp(
title:'Flutter Demo',
theme:ThemeData(
// This is the theme of your application.//// Try running your application with "flutter run". You'll see the// application has a blue toolbar. Then, without quitting the app, try// changing the primarySwatch below to Colors.green and then invoke// "hot reload" (press "r" in the console where you ran "flutter run",// or simply save your changes to "hot reload" in a Flutter IDE).// Notice that the counter didn't reset back to zero; the application// is not restarted.
primarySwatch:Colors.blue,
),
home:constMyHomePage(title:'Flutter Demo Home Page'),
);
}
}
classMyHomePageextendsStatefulWidget {
constMyHomePage({Key? key, requiredthis.title}) :super(key: key);
// This widget is the home page of your application. It is stateful, meaning// that it has a State object (defined below) that contains fields that affect// how it looks.// This class is the configuration for the state. It holds the values (in this// case the title) provided by the parent (in this case the App widget) and// used by the build method of the State. Fields in a Widget subclass are// always marked "final".finalString title;
@overrideState<MyHomePage> createState() =>_MyHomePageState();
}
class_MyHomePageStateextendsState<MyHomePage> {
finalScrollController _scrollController =ScrollController();
lateSliverObserverController observerController;
void_incrementCounter() {
// 动画滚动至下标位置
observerController.animateTo(
index:8,
duration:constDuration(seconds:1),
curve:Curves.ease,
);
}
@overridevoidinitState() {
observerController =SliverObserverController(controller: _scrollController);
super.initState();
}
@overrideWidgetbuild(BuildContext context) {
// This method is rerun every time setState is called, for instance as done// by the _incrementCounter method above.//// The Flutter framework has been optimized to make rerunning build methods// fast, so that you can just rebuild anything that needs updating rather// than having to individually change instances of widgets.returnScaffold(
appBar:AppBar(
// Here we take the value from the MyHomePage object that was created by// the App.build method, and use it to set our appbar title.
title:Text(widget.title),
),
body:SliverViewObserver(
controller: observerController,
child:CustomScrollView(
controller: _scrollController,
slivers:List.generate(
10,
(index) =>SliverToBoxAdapter(
child:GestureDetector(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) =>CustomScrollViewDemoPage(),
),
);
},
child:Container(
color:Colors.grey,
margin:constEdgeInsets.all(12),
child:Text(index.toString()),
height:100,
),
),
),
),
),
),
floatingActionButton:FloatingActionButton(
onPressed: _incrementCounter,
tooltip:'Increment',
child:constIcon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Try do it
这样搞没有效果,还需要额外实现其他方法吗?
The text was updated successfully, but these errors were encountered:
您好,有些场景不知道如何使用,能帮忙看一下吗? 谢谢。
Platforms
Android, iOS
Description
从demo上都在在解决CustomScrollView里面SliverList和SliverGrid的问题,没有看到有关其他sliver组件的解决方案。
My code
Try do it
这样搞没有效果,还需要额外实现其他方法吗?
The text was updated successfully, but these errors were encountered: