flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.54k stars 27.13k forks source link

Add displacement to CupertinoSliverRefreshControl #151756

Open Geara0 opened 1 month ago

Geara0 commented 1 month ago

Use case

I want my SliverList extend to the top of the screen, but then CupertinoSliverRefreshControl appears behind the iPhone notch.

Proposal

Would be nice to have a displacement parameter like in regular RefreshIndicator

It will be pretty easy to add. double? displacement - in constructor

displacement ?? _kActivityIndicatorMargin in this line: https://github.com/flutter/flutter/blob/9e88446f89c05659bc761c39519a407f89b25079/packages/flutter/lib/src/cupertino/refresh.dart#L393

Piinks commented 1 month ago

@Geara0 can you share more about your use case and provide maybe a picture or some sample code? Thank you!

Geara0 commented 1 month ago

@Piinks You can use following code as an example (Run it on iphone 15 pro max - notch completely blocks refresh indicator)

Of course, in this example you can add SliverAppBar. But sometimes there are cases when you can't

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          CupertinoSliverRefreshControl(
            onRefresh: () {
              return Future.delayed(const Duration(seconds: 5));
            },
          ),
          SliverList.separated(
            itemBuilder: (context, i) {
              return Container(
                color: Colors.blueGrey,
                height: 100,
              );
            },
            separatorBuilder: (_, __) => const SizedBox(height: 10),
          ),
        ],
      ),
    );
  }
}