美文网首页
sliver之SingleChildScrollView

sliver之SingleChildScrollView

作者: 码农_小斌哥 | 来源:发表于2023-05-18 15:12 被阅读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,
          ),
        ];
    }
    
    
    

    相关文章

      网友评论

          本文标题:sliver之SingleChildScrollView

          本文链接:https://www.haomeiwen.com/subject/sqfbtrtx.html