flutter3.0学习笔记

SliverSafeArea

Preview

SliverSafeArea作用跟SafeArea一样,SliverSafeArea是针对sliver。构造函数:

 const SliverSafeArea({
    super.key,
    this.left = true,
    this.top = true,
    this.right = true,
    this.bottom = true,
    this.minimum = EdgeInsets.zero,
    required this.sliver,
  }) 

例子:

import 'package:flutter/material.dart';

class SliverSafeAreaPage extends StatelessWidget {
  const SliverSafeAreaPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: WithSliverSafeArea(),
    );
  }

  Widget WithoutSliverSafeArea (){
    return const CustomScrollView(
      slivers: [
        SliverAppBar(title: Text('SliverSafeArea'),)
      ],
    );
  }
  Widget WithSliverSafeArea (){
    return const CustomScrollView(
      slivers: [
       SliverSafeArea(
          sliver:  SliverAppBar(title: Text('SliverSafeArea'),)
       )
      ],
    );
  }
}

image.png