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 RefreshFooter extends StatefulWidget {
  const RefreshFooter({Key? key}) : super(key: key);

  @override
  State<RefreshFooter> createState() => _RefreshFooterState();
}

class _RefreshFooterState extends State<RefreshFooter>
    with SingleTickerProviderStateMixin {
  @override
  void initState() {
    super.initState();
  }

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

  @override
  Widget build(BuildContext context) {
    return buildBody();
  }

  Widget buildBody() {
    TextStyle style = TextStyle(fontSize: ScreenAdaper.sp(18));
    return CustomFooter(
      builder: (BuildContext context, LoadStatus? status) {
        Widget body;
        if (status == LoadStatus.idle) {
          body = const Text("上拉获取更多");
        } else if (status == LoadStatus.loading) {
          body = const LoadingIndicator();
        } else if (status == LoadStatus.failed) {
          body = Text(
            "获取失败，请重试",
            style: style,
          );
        } else if (status == LoadStatus.canLoading) {
          body = const LoadingIndicator(
            animating: false,
          );
        } else {
          body = const SizedBox();
        }
        return SizedBox(
          height: ScreenAdaper.height(20),
          child: Center(child: body),
        );
      },
    );
  }
}
