Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'dart:async';
- class CustomRefreshIndicator extends StatefulWidget {
- const CustomRefreshIndicator({
- Key key,
- this.child,
- this.displacement: 40.0,
- this.onRefresh,
- this.color,
- this.backgroundColor,
- this.notificationPredicate: defaultScrollNotificationPredicate,
- this.isFirstRefresh,
- }) : assert(child != null),
- assert(onRefresh != null),
- assert(notificationPredicate != null),
- super(key: key);
- final Widget child;
- final double displacement;
- final RefreshCallback onRefresh;
- final Color color;
- final Color backgroundColor;
- final ScrollNotificationPredicate notificationPredicate;
- final bool isFirstRefresh;
- @override
- CustomRefreshIndicatorState createState() =>
- new CustomRefreshIndicatorState();
- }
- class CustomRefreshIndicatorState extends State<CustomRefreshIndicator> {
- final GlobalKey<RefreshIndicatorState> _refreshKey =
- new GlobalKey<RefreshIndicatorState>();
- @override
- void initState() {
- super.initState();
- if (widget.isFirstRefresh) {
- _initRefreshAsync();
- }
- }
- void _initRefreshAsync() async {
- while (_refreshKey.currentState == null) {
- await Future.delayed(const Duration(
- milliseconds: 17)); //Wait about 1 frame, try every frame
- }
- _refreshKey.currentState.show();
- }
- @override
- Widget build(BuildContext context) {
- return new RefreshIndicator(
- key: _refreshKey,
- child: widget.child,
- displacement: widget.displacement,
- onRefresh: widget.onRefresh,
- color: widget.color,
- backgroundColor: widget.backgroundColor,
- notificationPredicate: widget.notificationPredicate,
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement