homeScreen static method

String homeScreen({
  1. required String name,
  2. required String title,
  3. required String designDir,
  4. required String className,
  5. required String providerName,
  6. List<String> providerImports = const [],
  7. String inlineProvider = '',
})

The home screen / view — a ConsumerWidget rendering an AsyncValue.when body. The watched provider must expose an object with title and subtitle String fields.

  • className widget class name (HomeScreen / HomeView)
  • designDir design-system folder relative to lib/
  • providerName the FutureProvider being watched
  • providerImports import lines for the provider (empty if inline)
  • inlineProvider optional provider definition placed in this file

Implementation

static String homeScreen({
  required String name,
  required String title,
  required String designDir,
  required String className,
  required String providerName,
  List<String> providerImports = const [],
  String inlineProvider = '',
}) {
  final providerImportLines = providerImports
      .map((path) => "import 'package:$name/$path';")
      .join('\n');
  final inlineBlock = inlineProvider.isEmpty ? '' : '\n$inlineProvider\n';

  return '''
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:$name/$designDir/app_colors.dart';
import 'package:$name/$designDir/app_spacing.dart';
import 'package:$name/$designDir/app_text_styles.dart';${providerImportLines.isEmpty ? '' : '\n$providerImportLines'}
$inlineBlock
class $className extends ConsumerWidget {
const $className({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
  final state = ref.watch($providerName);

  return Scaffold(
    appBar: AppBar(title: const Text('$title')),
    body: SafeArea(
      child: Padding(
        padding: const EdgeInsets.all(AppSpacing.lg),
        child: state.when(
          loading: () =>
              const Center(child: CircularProgressIndicator()),
          error: (e, _) => Center(
            child: Text(
              'Error: \$e',
              style: AppTextStyles.body.copyWith(color: AppColors.error),
            ),
          ),
          data: (data) => Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(data.title, style: AppTextStyles.h1),
              const SizedBox(height: AppSpacing.sm),
              Text(data.subtitle, style: AppTextStyles.body),
              const Spacer(),
              Center(
                child: ElevatedButton(
                  onPressed: () => ref.invalidate($providerName),
                  child: const Text('Refresh'),
                ),
              ),
              const SizedBox(height: AppSpacing.lg),
              const Center(
                child: Text(
                  'Generated by srik_cli',
                  style: AppTextStyles.caption,
                ),
              ),
            ],
          ),
        ),
      ),
    ),
  );
}
}
''';
}