generateProfileScreen static method

String generateProfileScreen(
  1. String projectName
)

Generates a responsive profile screen with enhanced widgets

Implementation

static String generateProfileScreen(String projectName) {
  return '''
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../../shared/widgets/widgets.dart';

class ProfileScreen extends StatelessWidget {
const ProfileScreen({Key? key}) : super(key: key);

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

  return Scaffold(
    body: CustomScrollView(
      slivers: [
        // App Bar with Gradient
        SliverAppBar(
          expandedHeight: 200,
          pinned: true,
          leading: IconButton(
            icon: const Icon(Icons.arrow_back_ios_new, size: 20),
            onPressed: () => context.go('/'),
          ),
          actions: [
            IconButton(
              icon: const Icon(Icons.edit_outlined),
              onPressed: () {},
            ),
            const SizedBox(width: 8),
          ],
          flexibleSpace: FlexibleSpaceBar(
            title: const Text(
              'Profile',
              style: TextStyle(
                fontWeight: FontWeight.bold,
                letterSpacing: 0.5,
              ),
            ),
            background: Container(
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.topLeft,
                  end: Alignment.bottomRight,
                  colors: [
                    theme.colorScheme.primary,
                    theme.colorScheme.secondary,
                  ],
                ),
              ),
            ),
          ),
        ),

        // Profile Card
        SliverPadding(
          padding: const EdgeInsets.fromLTRB(20, 24, 20, 0),
          sliver: SliverToBoxAdapter(
            child: ProfileCard(
              name: 'John Doe',
              email: 'john.doe@example.com',
              subtitle: 'Premium Member',
              onTap: () {},
              actions: [
                ProfileAction(
                  label: 'Edit',
                  icon: Icons.edit_outlined,
                  onTap: () {},
                ),
                ProfileAction(
                  label: 'Share',
                  icon: Icons.share_outlined,
                  onTap: () {},
                ),
                ProfileAction(
                  label: 'QR Code',
                  icon: Icons.qr_code_2_rounded,
                  onTap: () {},
                ),
              ],
            ),
          ),
        ),

        const SliverToBoxAdapter(child: SizedBox(height: 24)),

        // Stats Section
        SliverPadding(
          padding: const EdgeInsets.symmetric(horizontal: 20),
          sliver: SliverToBoxAdapter(
            child: Card(
              elevation: 0,
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(20),
                side: BorderSide(
                  color: theme.colorScheme.outline.withOpacity(0.1),
                ),
              ),
              child: Padding(
                padding: const EdgeInsets.all(20),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    _buildStatItem(context, '124', 'Posts'),
                    _buildDivider(theme),
                    _buildStatItem(context, '2.4K', 'Followers'),
                    _buildDivider(theme),
                    _buildStatItem(context, '892', 'Following'),
                  ],
                ),
              ),
            ),
          ),
        ),

        const SliverToBoxAdapter(child: SizedBox(height: 32)),

        // Settings Section
        SliverPadding(
          padding: const EdgeInsets.symmetric(horizontal: 20),
          sliver: SliverToBoxAdapter(
            child: Text(
              'Settings',
              style: theme.textTheme.titleLarge?.copyWith(
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
        ),

        const SliverToBoxAdapter(child: SizedBox(height: 16)),

        SliverPadding(
          padding: const EdgeInsets.symmetric(horizontal: 20),
          sliver: SliverToBoxAdapter(
            child: Column(
              children: [
                _buildSettingsGroup(
                  context,
                  'Account Settings',
                  [
                    _buildSettingsTile(
                      context,
                      'Account Information',
                      Icons.person_outline_rounded,
                      () {},
                    ),
                    _buildSettingsTile(
                      context,
                      'Security',
                      Icons.security_outlined,
                      () {},
                    ),
                    _buildSettingsTile(
                      context,
                      'Privacy',
                      Icons.privacy_tip_outlined,
                      () {},
                    ),
                  ],
                ),
                const SizedBox(height: 16),
                _buildSettingsGroup(
                  context,
                  'Preferences',
                  [
                    _buildSettingsTile(
                      context,
                      'Theme',
                      isDark ? Icons.dark_mode : Icons.light_mode,
                      () {},
                      trailing: Switch(
                        value: isDark,
                        onChanged: (value) {
                          // TODO: Implement theme toggle
                        },
                      ),
                    ),
                    _buildSettingsTile(
                      context,
                      'Notifications',
                      Icons.notifications_outlined,
                      () {},
                    ),
                    _buildSettingsTile(
                      context,
                      'Language',
                      Icons.language_rounded,
                      () {},
                      subtitle: 'English',
                    ),
                  ],
                ),
                const SizedBox(height: 16),
                _buildSettingsGroup(
                  context,
                  'Support',
                  [
                    _buildSettingsTile(
                      context,
                      'Help & Support',
                      Icons.help_outline_rounded,
                      () {},
                    ),
                    _buildSettingsTile(
                      context,
                      'Terms of Service',
                      Icons.description_outlined,
                      () {},
                    ),
                    _buildSettingsTile(
                      context,
                      'About',
                      Icons.info_outline_rounded,
                      () {},
                      subtitle: 'Version 1.0.0',
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),

        const SliverToBoxAdapter(child: SizedBox(height: 32)),

        // Logout Button
        SliverPadding(
          padding: const EdgeInsets.symmetric(horizontal: 20),
          sliver: SliverToBoxAdapter(
            child: SizedBox(
              width: double.infinity,
              height: 56,
              child: OutlinedButton.icon(
                onPressed: () async {
                  final result = await ConfirmDialog.show(
                    context,
                    title: 'Logout',
                    message: 'Are you sure you want to logout?',
                    confirmText: 'Logout',
                    isDestructive: true,
                    icon: Icons.logout_rounded,
                  );

                  if (result == true) {
                    // TODO: Implement logout
                    if (context.mounted) {
                      context.go('/login');
                    }
                  }
                },
                style: OutlinedButton.styleFrom(
                  side: BorderSide(
                    color: theme.colorScheme.error,
                    width: 1.5,
                  ),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(16),
                  ),
                ),
                icon: Icon(
                  Icons.logout_rounded,
                  color: theme.colorScheme.error,
                ),
                label: Text(
                  'Logout',
                  style: TextStyle(
                    color: theme.colorScheme.error,
                    fontSize: 16,
                    fontWeight: FontWeight.w600,
                  ),
                ),
              ),
            ),
          ),
        ),

        const SliverToBoxAdapter(child: SizedBox(height: 40)),
      ],
    ),
  );
}

Widget _buildStatItem(BuildContext context, String value, String label) {
  final theme = Theme.of(context);
  return Column(
    children: [
      Text(
        value,
        style: theme.textTheme.headlineSmall?.copyWith(
          fontWeight: FontWeight.bold,
        ),
      ),
      const SizedBox(height: 4),
      Text(
        label,
        style: theme.textTheme.bodyMedium?.copyWith(
          color: theme.colorScheme.onSurface.withOpacity(0.6),
        ),
      ),
    ],
  );
}

Widget _buildDivider(ThemeData theme) {
  return Container(
    height: 40,
    width: 1,
    color: theme.colorScheme.outline.withOpacity(0.2),
  );
}

Widget _buildSettingsGroup(
  BuildContext context,
  String title,
  List<Widget> children,
) {
  final theme = Theme.of(context);
  return Card(
    elevation: 0,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(20),
      side: BorderSide(
        color: theme.colorScheme.outline.withOpacity(0.1),
      ),
    ),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Padding(
          padding: const EdgeInsets.fromLTRB(20, 16, 20, 12),
          child: Text(
            title,
            style: theme.textTheme.titleSmall?.copyWith(
              fontWeight: FontWeight.w600,
              color: theme.colorScheme.onSurface.withOpacity(0.6),
            ),
          ),
        ),
        ...children,
      ],
    ),
  );
}

Widget _buildSettingsTile(
  BuildContext context,
  String title,
  IconData icon,
  VoidCallback onTap, {
  String? subtitle,
  Widget? trailing,
}) {
  final theme = Theme.of(context);

  return ListTile(
    leading: Container(
      padding: const EdgeInsets.all(8),
      decoration: BoxDecoration(
        color: theme.colorScheme.primary.withOpacity(0.1),
        borderRadius: BorderRadius.circular(12),
      ),
      child: Icon(
        icon,
        color: theme.colorScheme.primary,
        size: 22,
      ),
    ),
    title: Text(
      title,
      style: const TextStyle(
        fontWeight: FontWeight.w500,
      ),
    ),
    subtitle: subtitle != null
        ? Text(
            subtitle,
            style: TextStyle(
              fontSize: 12,
              color: theme.colorScheme.onSurface.withOpacity(0.5),
            ),
          )
        : null,
    trailing: trailing ?? const Icon(Icons.chevron_right, size: 20),
    onTap: trailing == null ? onTap : null,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(12),
    ),
  );
}
}
''';
}