loadingUi method

Widget loadingUi({
  1. required CkAuthLoadingType type,
  2. required Widget builder(
    1. bool isLoading
    ),
})

A simplified reactive StreamBuilder UI helper for auth operation loading states.

Pass the type of auth operation to observe, and the builder receives only a bool indicating whether that operation is loading.

Example:

auth.loadingUi(
  type: CkAuthLoadingType.signIn,
  builder: (isLoading) => ElevatedButton(
    onPressed: isLoading ? null : () => auth.signIn(...),
    child: isLoading ? CircularProgressIndicator() : Text('Sign In'),
  ),
)

Implementation

Widget loadingUi({
  required CkAuthLoadingType type,
  required Widget Function(bool isLoading) builder,
}) {
  final stream = loadingController.streamOf(type);
  return StreamBuilder<bool>(
    stream: stream.stream,
    initialData: stream.value,
    builder: (context, snapshot) {
      if (snapshot.hasError) {
        return builder(false);
      }
      return builder(snapshot.data ?? false);
    },
  );
}