generateAppLoader static method

String generateAppLoader()

Implementation

static String generateAppLoader() {
  return '''
import 'package:flutter/material.dart';

class AppLoader extends StatelessWidget {
final double size;
final Color? color;
final String? message;
final bool isFullScreen;

const AppLoader({
  Key? key,
  this.size = 48,
  this.color,
  this.message,
  this.isFullScreen = false,
}) : super(key: key);

@override
Widget build(BuildContext context) {
  final theme = Theme.of(context);
  final loaderColor = color ?? theme.colorScheme.primary;

  final loader = Column(
    mainAxisSize: MainAxisSize.min,
    children: [
      SizedBox(
        width: size,
        height: size,
        child: CircularProgressIndicator(
          strokeWidth: 3.5,
          valueColor: AlwaysStoppedAnimation<Color>(loaderColor),
        ),
      ),
      if (message != null) ...[
        const SizedBox(height: 20),
        Text(
          message!,
          style: theme.textTheme.bodyLarge?.copyWith(
            fontWeight: FontWeight.w500,
          ),
          textAlign: TextAlign.center,
        ),
      ],
    ],
  );

  if (isFullScreen) {
    return Scaffold(
      backgroundColor: theme.scaffoldBackgroundColor,
      body: Center(child: loader),
    );
  }

  return Center(child: loader);
}
}

class OverlayLoader extends StatelessWidget {
final String? message;

const OverlayLoader({Key? key, this.message}) : super(key: key);

@override
Widget build(BuildContext context) {
  return Container(
    color: Colors.black.withOpacity(0.6),
    child: Center(
      child: Card(
        margin: const EdgeInsets.all(32),
        child: Padding(
          padding: const EdgeInsets.all(32),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              const CircularProgressIndicator(
                valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
              ),
              if (message != null) ...[
                const SizedBox(height: 20),
                Text(
                  message!,
                  style: const TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.w500,
                    color: Colors.white,
                  ),
                  textAlign: TextAlign.center,
                ),
              ],
            ],
          ),
        ),
      ),
    ),
  );
}
}

class LinearLoader extends StatelessWidget {
final String? message;
final double? value;

const LinearLoader({
  Key? key,
  this.message,
  this.value,
}) : super(key: key);

@override
Widget build(BuildContext context) {
  final theme = Theme.of(context);

  return Column(
    mainAxisSize: MainAxisSize.min,
    children: [
      if (message != null) ...[
        Text(
          message!,
          style: theme.textTheme.bodyMedium,
        ),
        const SizedBox(height: 12),
      ],
      ClipRRect(
        borderRadius: BorderRadius.circular(8),
        child: LinearProgressIndicator(
          value: value,
          minHeight: 6,
          backgroundColor: theme.colorScheme.surfaceVariant,
          valueColor: AlwaysStoppedAnimation<Color>(
            theme.colorScheme.primary,
          ),
        ),
      ),
    ],
  );
}
}
''';
}