homeScreen static method
The home screen / view — a ConsumerWidget rendering an AsyncValue.when
body. The watched provider must expose an object with title and
subtitle String fields.
classNamewidget class name (HomeScreen / HomeView)designDirdesign-system folder relative to lib/providerNamethe FutureProvider being watchedproviderImportsimport lines for the provider (empty if inline)inlineProvideroptional 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/design_system.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: AppSurface(
depth: AppSurfaceDepth.flat,
padding: EdgeInsets.zero,
child: 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: AppTypography.body.copyWith(color: AppColors.error),
),
),
data: (data) => Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
AppCard(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(data.title, style: AppTypography.display),
const SizedBox(height: AppSpacing.sm),
Text(data.subtitle, style: AppTypography.body),
const SizedBox(height: AppSpacing.md),
AppChip(label: AppStyleConfig.style.label),
],
),
),
const Spacer(),
AppButton(
label: 'Refresh',
onPressed: () => ref.invalidate($providerName),
),
const SizedBox(height: AppSpacing.sm),
AppButton(
label: 'Secondary',
variant: AppButtonVariant.secondary,
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Secondary action')),
);
},
),
const SizedBox(height: AppSpacing.lg),
const Center(
child: Text(
'Generated by srik_cli',
style: AppTypography.caption,
),
),
],
),
),
),
),
),
);
}
}
''';
}