一统天下 flutter - widget Sliver: SliverToBoxAdapter - 为不可滚动组件提供 sliver 效果

源码 https://github.com/webabcd/flutter_demo
作者 webabcd

一统天下 flutter - widget Sliver: SliverToBoxAdapter - 为不可滚动组件提供 sliver 效果

示例如下:

lib\widget\sliver\sliver_to_box_adapter.dart

/*
 * SliverToBoxAdapter - 为不可滚动组件提供 sliver 效果
 */

import 'package:flutter/material.dart';

import '../../helper.dart';

class SliverToBoxAdapterDemo extends StatefulWidget {
  const SliverToBoxAdapterDemo({Key? key}) : super(key: key);

  @override
  _SliverToBoxAdapterDemoState createState() => _SliverToBoxAdapterDemoState();
}

class _SliverToBoxAdapterDemoState extends State<SliverToBoxAdapterDemo> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.orange,
      body: CustomScrollView(
        /// 指定 slivers
        slivers: [
          SliverAppBar(
            title: const Text('title'),
            expandedHeight: 200,
            flexibleSpace: FlexibleSpaceBar(
              background: Image.asset('assets/son.jpg',fit: BoxFit.cover,),
            ),
            pinned: true,
          ),

          /// SliverToBoxAdapter - 为不可滚动组件提供 sliver 效果
          SliverToBoxAdapter(
            /// 一个不可滚动组件
            child: Column(
              children: [for (var i = 0; i < 100; i++) MyText(i.toString())],
            ),
          ),
        ],
      ),
    );
  }
}

源码 https://github.com/webabcd/flutter_demo
作者 webabcd

posted @ 2023-04-23 16:46  webabcd  阅读(154)  评论(0编辑  收藏  举报