import 'package:flutter/material.dart';
import 'package:initial_folder/providers/certificate_provider.dart';
import 'package:initial_folder/screens/certificate/component/all_certificate_header.dart';

import 'package:initial_folder/screens/certificate/component/all_certificate_item.dart';
import 'package:provider/provider.dart';

import '../../size_config.dart';
import '../../theme.dart';

class AllCertificate extends StatelessWidget {
  const AllCertificate({Key? key, this.isLogin}) : super(key: key);

  final bool? isLogin;

  @override
  Widget build(BuildContext context) {
    Future.delayed(Duration(seconds: 0), () async {
      await Provider.of<CertificateProvider>(context, listen: false)
          .getAllCertif();
    });

    return isLogin != null
        ? Scaffold(
            appBar: AppBar(
              backgroundColor: Theme.of(context).colorScheme.background,
            ),
            body: Center(
              child: Text("Silahkan login terlebih dahulu"),
            ),
          )
        : Scaffold(
            resizeToAvoidBottomInset: false,
            appBar: AppBar(
              backgroundColor: Theme.of(context).colorScheme.background,
              centerTitle: true,
              title: Text(
                'Sertifikat',
                style: secondaryTextStyle.copyWith(
                  letterSpacing: 1,
                  fontWeight: semiBold,
                  fontSize: getProportionateScreenWidth(16),
                ),
              ),
            ),
            body: RefreshIndicator(
              displacement: 40,
              color: primaryColor,
              onRefresh: () async {
                await Provider.of<CertificateProvider>(context, listen: false)
                    .getAllCertif();
              },
              child: Padding(
                padding: EdgeInsets.only(
                  top: getProportionateScreenWidth(5),
                  right: getProportionateScreenWidth(20),
                  left: getProportionateScreenWidth(20),
                ),
                child: ListView(
                  children: [
                    CertificateHeader(),
                    CertificateItem(),
                  ],
                ),
              ),
            ),
          );
  }
}
