screen static method

String screen(
  1. String projectName,
  2. String feature,
  3. String designDir
)

Implementation

static String screen(String projectName, String feature, String designDir) {
  final pascal = StringUtils.toPascalCase(feature);
  final title = StringUtils.toTitleCase(feature);
  return '''
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:$projectName/$designDir/app_colors.dart';
import 'package:$projectName/$designDir/app_spacing.dart';
import 'package:$projectName/$designDir/app_text_styles.dart';
import 'package:$projectName/features/$feature/presentation/providers/${feature}_provider.dart';

class ${pascal}Screen extends ConsumerWidget {
const ${pascal}Screen({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
  final asyncValue = ref.watch(${feature}Provider);

  return Scaffold(
    appBar: AppBar(title: const Text('$title')),
    body: SafeArea(
      child: Padding(
        padding: const EdgeInsets.all(AppSpacing.lg),
        child: asyncValue.when(
          loading: () =>
              const Center(child: CircularProgressIndicator()),
          error: (e, _) => Center(
            child: Text(
              'Error: \$e',
              style: AppTextStyles.body.copyWith(color: AppColors.error),
            ),
          ),
          data: (entity) => Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              const Text('$title', style: AppTextStyles.h1),
              const SizedBox(height: AppSpacing.sm),
              Text('id: \${entity.id}', style: AppTextStyles.body),
            ],
          ),
        ),
      ),
    ),
  );
}
}
''';
}