sliver之SingleChildScrollView
2023-05-18 本文已影响0人
码农_小斌哥
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class SingleChildScrollViewTest extends StatefulWidget {
const SingleChildScrollViewTest({Key? key}) : super(key: key);
@override
_SingleChildScrollViewTestState createState() => _SingleChildScrollViewTestState();
}
class _SingleChildScrollViewTestState extends State<SingleChildScrollViewTest> {
late ScrollController _scrollController;
@override
void initState() {
super.initState();
_scrollController = ScrollController(initialScrollOffset: 0);
}
/**
*有一个子widget的可滚动的widget,子内容超过父容器时可以滚动
*scrollDirection = Axis.vertical:滑动方向
*reverse = false:是否倒序
*padding:内边距
*primary:当内容不足以滚动时,是否支持滚动;
*physics:控制用户滚动视图的交互
*controller:滑动控制器
*child:*/
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('SingleChildScrollViewTest'),
),
body: SingleChildScrollView(
controller: _scrollController,
reverse: true,
child: ListBody(
children: _myChildren(),
),
restorationId: "sss",
),
);
_myChildren() {
return [
Container(
height: 300,
color: Colors.blue,
),
Container(
height: 300,
color: Colors.yellow,
),
Container(
height: 300,
color: Colors.red,
),
Container(
height: 300,
color: Colors.green,
),
];
}