import 'package:flutter/cupertino.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:sk_base_mobile/app_theme.dart';
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
import 'package:sk_base_mobile/widgets/loading_indicator.dart';

class RefreshHeader extends RefreshIndicator {
  RefreshHeader()
      : super(
            height: ScreenAdaper.height(100),
            refreshStyle: RefreshStyle.Follow);
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return RefreshHeaderState();
  }
}

class RefreshHeaderState extends RefreshIndicatorState<RefreshHeader>
    with SingleTickerProviderStateMixin {
  @override
  void initState() {
    super.initState();
  }

  @override
  void onModeChange(RefreshStatus? mode) {
    super.onModeChange(mode);
  }

  @override
  Future<void> endRefresh() async {}

  @override
  void resetValue() {
    super.resetValue();
  }

  @override
  Widget buildContent(BuildContext context, RefreshStatus mode) {
    TextStyle style = TextStyle(fontSize: ScreenAdaper.sp(18));
    Widget body;
    if (mode == RefreshStatus.refreshing) {
      body = const LoadingIndicator();
    } else if (mode == RefreshStatus.canRefresh) {
      body = const LoadingIndicator(
        animating: false,
      );
    } else if (mode == RefreshStatus.completed) {
      body = const SizedBox();
    } else if (mode == RefreshStatus.failed) {
      body = Text("没有更多数据了", style: style);
    } else {
      body = const LoadingIndicator();
    }
    return SizedBox(
      height: ScreenAdaper.height(40),
      child: Center(child: body),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
