Compare commits

..

1 Commits

Author SHA1 Message Date
e39b4b64cc demo 2025-10-01 08:15:05 +07:00
29 changed files with 1284 additions and 1693 deletions

View File

@@ -1,41 +1,60 @@
PODS: PODS:
- audioplayers_darwin (0.0.1):
- Flutter
- FlutterMacOS
- connectivity_plus (0.0.1): - connectivity_plus (0.0.1):
- Flutter - Flutter
- Flutter (1.0.0) - Flutter (1.0.0)
- flutter_secure_storage (6.0.0): - flutter_secure_storage (6.0.0):
- Flutter - Flutter
- flutter_tts (0.0.1):
- Flutter
- path_provider_foundation (0.0.1): - path_provider_foundation (0.0.1):
- Flutter - Flutter
- FlutterMacOS - FlutterMacOS
- record_ios (1.1.0):
- Flutter
- sqflite_darwin (0.0.4): - sqflite_darwin (0.0.4):
- Flutter - Flutter
- FlutterMacOS - FlutterMacOS
DEPENDENCIES: DEPENDENCIES:
- audioplayers_darwin (from `.symlinks/plugins/audioplayers_darwin/darwin`)
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`) - connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
- Flutter (from `Flutter`) - Flutter (from `Flutter`)
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`) - flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
- flutter_tts (from `.symlinks/plugins/flutter_tts/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- record_ios (from `.symlinks/plugins/record_ios/ios`)
- sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`) - sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)
EXTERNAL SOURCES: EXTERNAL SOURCES:
audioplayers_darwin:
:path: ".symlinks/plugins/audioplayers_darwin/darwin"
connectivity_plus: connectivity_plus:
:path: ".symlinks/plugins/connectivity_plus/ios" :path: ".symlinks/plugins/connectivity_plus/ios"
Flutter: Flutter:
:path: Flutter :path: Flutter
flutter_secure_storage: flutter_secure_storage:
:path: ".symlinks/plugins/flutter_secure_storage/ios" :path: ".symlinks/plugins/flutter_secure_storage/ios"
flutter_tts:
:path: ".symlinks/plugins/flutter_tts/ios"
path_provider_foundation: path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin" :path: ".symlinks/plugins/path_provider_foundation/darwin"
record_ios:
:path: ".symlinks/plugins/record_ios/ios"
sqflite_darwin: sqflite_darwin:
:path: ".symlinks/plugins/sqflite_darwin/darwin" :path: ".symlinks/plugins/sqflite_darwin/darwin"
SPEC CHECKSUMS: SPEC CHECKSUMS:
connectivity_plus: 2a701ffec2c0ae28a48cf7540e279787e77c447d audioplayers_darwin: 4f9ca89d92d3d21cec7ec580e78ca888e5fb68bd
connectivity_plus: cb623214f4e1f6ef8fe7403d580fdad517d2f7dd
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467 Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467
flutter_secure_storage: d33dac7ae2ea08509be337e775f6b59f1ff45f12 flutter_secure_storage: 1ed9476fba7e7a782b22888f956cce43e2c62f13
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46 flutter_tts: b88dbc8655d3dc961bc4a796e4e16a4cc1795833
sqflite_darwin: 5a7236e3b501866c1c9befc6771dfd73ffb8702d path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
record_ios: f75fa1d57f840012775c0e93a38a7f3ceea1a374
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
PODFILE CHECKSUM: 3c63482e143d1b91d2d2560aee9fb04ecc74ac7e PODFILE CHECKSUM: 3c63482e143d1b91d2d2560aee9fb04ecc74ac7e

View File

@@ -20,6 +20,8 @@
<string>$(FLUTTER_BUILD_NAME)</string> <string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>NSMicrophoneUsageDescription</key>
<string>Some message to describe why you need this permission</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string> <string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>

View File

@@ -1,6 +1,7 @@
/// Environment configuration for API endpoints and settings /// Environment configuration for API endpoints and settings
enum Environment { enum Environment {
development, development,
staging,
production, production,
} }
@@ -12,75 +13,107 @@ class EnvironmentConfig {
/// Current environment - Change this to switch environments /// Current environment - Change this to switch environments
static const Environment currentEnvironment = Environment.development; static const Environment currentEnvironment = Environment.development;
/// Environment configurations as JSON map for easy editing
static const Map<Environment, Map<String, dynamic>> _configs = {
Environment.development: {
'baseUrl': 'http://103.188.82.191:4003',
'apiPath': '',
'connectTimeout': 30000,
'receiveTimeout': 30000,
'sendTimeout': 30000,
'enableLogging': true,
'enableDetailedLogging': true,
'enableCertificatePinning': false,
'maxRetries': 3,
'retryDelay': 1000, // milliseconds
},
Environment.production: {
'baseUrl': 'https://api.example.com',
'apiPath': '/api/v1',
'connectTimeout': 30000,
'receiveTimeout': 30000,
'sendTimeout': 30000,
'enableLogging': false,
'enableDetailedLogging': false,
'enableCertificatePinning': true,
'maxRetries': 3,
'retryDelay': 1000, // milliseconds
},
};
/// Get current environment configuration
static Map<String, dynamic> get _currentConfig => _configs[currentEnvironment]!;
/// Get base URL for current environment /// Get base URL for current environment
static String get baseUrl => _currentConfig['baseUrl'] as String; static String get baseUrl {
switch (currentEnvironment) {
case Environment.development:
return 'http://localhost:3000';
case Environment.staging:
return 'https://api-staging.example.com';
case Environment.production:
return 'https://api.example.com';
}
}
/// Get API path for current environment /// Get API path for current environment
static String get apiPath => _currentConfig['apiPath'] as String; static String get apiPath {
switch (currentEnvironment) {
case Environment.development:
// No API prefix for local development - endpoints are directly at /auth/
return '';
case Environment.staging:
case Environment.production:
return '/api/v1';
}
}
/// Check if current environment is development /// Check if current environment is development
static bool get isDevelopment => currentEnvironment == Environment.development; static bool get isDevelopment => currentEnvironment == Environment.development;
/// Check if current environment is staging
static bool get isStaging => currentEnvironment == Environment.staging;
/// Check if current environment is production /// Check if current environment is production
static bool get isProduction => currentEnvironment == Environment.production; static bool get isProduction => currentEnvironment == Environment.production;
/// Check if current environment is staging (for backward compatibility, always false) /// Get timeout configurations based on environment
static bool get isStaging => false; static int get connectTimeout {
switch (currentEnvironment) {
case Environment.development:
return 10000; // 10 seconds for local development
case Environment.staging:
return 20000; // 20 seconds for staging
case Environment.production:
return 30000; // 30 seconds for production
}
}
/// Timeout configurations from config map static int get receiveTimeout {
static int get connectTimeout => _currentConfig['connectTimeout'] as int; switch (currentEnvironment) {
static int get receiveTimeout => _currentConfig['receiveTimeout'] as int; case Environment.development:
static int get sendTimeout => _currentConfig['sendTimeout'] as int; return 15000; // 15 seconds for local development
case Environment.staging:
return 25000; // 25 seconds for staging
case Environment.production:
return 30000; // 30 seconds for production
}
}
/// Enable/disable features from config map static int get sendTimeout {
static bool get enableLogging => _currentConfig['enableLogging'] as bool; switch (currentEnvironment) {
static bool get enableDetailedLogging => _currentConfig['enableDetailedLogging'] as bool; case Environment.development:
static bool get enableCertificatePinning => _currentConfig['enableCertificatePinning'] as bool; return 15000; // 15 seconds for local development
case Environment.staging:
return 25000; // 25 seconds for staging
case Environment.production:
return 30000; // 30 seconds for production
}
}
/// Retry configurations /// Get retry configurations based on environment
static int get maxRetries => _currentConfig['maxRetries'] as int; static int get maxRetries {
static Duration get retryDelay => Duration(milliseconds: _currentConfig['retryDelay'] as int); switch (currentEnvironment) {
case Environment.development:
return 2; // Fewer retries for local development
case Environment.staging:
return 3; // Standard retries for staging
case Environment.production:
return 3; // Standard retries for production
}
}
/// Authentication endpoints static Duration get retryDelay {
switch (currentEnvironment) {
case Environment.development:
return const Duration(milliseconds: 500); // Faster retry for local
case Environment.staging:
return const Duration(seconds: 1); // Standard retry delay
case Environment.production:
return const Duration(seconds: 1); // Standard retry delay
}
}
/// Enable/disable features based on environment
static bool get enableLogging => !isProduction;
static bool get enableDetailedLogging => isDevelopment;
static bool get enableCertificatePinning => isProduction;
/// Authentication endpoints (consistent across environments)
static const String authEndpoint = '/auth'; static const String authEndpoint = '/auth';
static const String loginEndpoint = '$authEndpoint/login'; static const String loginEndpoint = '$authEndpoint/login';
static const String registerEndpoint = '$authEndpoint/register'; static const String registerEndpoint = '$authEndpoint/register';
static const String refreshEndpoint = '$authEndpoint/refresh'; static const String refreshEndpoint = '$authEndpoint/refresh';
static const String logoutEndpoint = '$authEndpoint/logout'; static const String logoutEndpoint = '$authEndpoint/logout';
static const String resetPasswordEndpoint = '$authEndpoint/reset-password';
static const String changePasswordEndpoint = '$authEndpoint/change-password';
static const String verifyEmailEndpoint = '$authEndpoint/verify-email';
/// Full API URLs /// Full API URLs
static String get fullBaseUrl => baseUrl + apiPath; static String get fullBaseUrl => baseUrl + apiPath;
@@ -88,43 +121,20 @@ class EnvironmentConfig {
static String get registerUrl => baseUrl + registerEndpoint; static String get registerUrl => baseUrl + registerEndpoint;
static String get refreshUrl => baseUrl + refreshEndpoint; static String get refreshUrl => baseUrl + refreshEndpoint;
static String get logoutUrl => baseUrl + logoutEndpoint; static String get logoutUrl => baseUrl + logoutEndpoint;
static String get resetPasswordUrl => baseUrl + resetPasswordEndpoint;
static String get changePasswordUrl => baseUrl + changePasswordEndpoint;
static String get verifyEmailUrl => baseUrl + verifyEmailEndpoint;
/// User endpoints
static const String userEndpoint = '/user';
static const String profileEndpoint = '$userEndpoint/profile';
static const String updateProfileEndpoint = '$userEndpoint/update';
static const String deleteAccountEndpoint = '$userEndpoint/delete';
/// Full User URLs
static String get profileUrl => baseUrl + profileEndpoint;
static String get updateProfileUrl => baseUrl + updateProfileEndpoint;
static String get deleteAccountUrl => baseUrl + deleteAccountEndpoint;
/// Todo endpoints
static const String todosEndpoint = '/todo';
/// Full Todo URLs
static String get todosUrl => baseUrl + todosEndpoint;
/// Debug information /// Debug information
static Map<String, dynamic> get debugInfo => { static Map<String, dynamic> get debugInfo => {
'environment': currentEnvironment.name, 'environment': currentEnvironment.name,
'config': _currentConfig, 'baseUrl': baseUrl,
'endpoints': { 'apiPath': apiPath,
'login': loginUrl, 'fullBaseUrl': fullBaseUrl,
'register': registerUrl, 'connectTimeout': connectTimeout,
'refresh': refreshUrl, 'receiveTimeout': receiveTimeout,
'logout': logoutUrl, 'sendTimeout': sendTimeout,
'profile': profileUrl, 'maxRetries': maxRetries,
}, 'retryDelay': retryDelay.inMilliseconds,
'enableLogging': enableLogging,
'enableDetailedLogging': enableDetailedLogging,
'enableCertificatePinning': enableCertificatePinning,
}; };
/// Get a specific config value
static T? getConfig<T>(String key) => _currentConfig[key] as T?;
/// Check if a config key exists
static bool hasConfig(String key) => _currentConfig.containsKey(key);
} }

View File

@@ -9,12 +9,12 @@ class ApiConstants {
static String get baseUrl => EnvironmentConfig.baseUrl; static String get baseUrl => EnvironmentConfig.baseUrl;
static String get apiPath => EnvironmentConfig.apiPath; static String get apiPath => EnvironmentConfig.apiPath;
// Timeout configurations // Timeout configurations (environment-specific)
static int get connectTimeout => EnvironmentConfig.connectTimeout; static int get connectTimeout => EnvironmentConfig.connectTimeout;
static int get receiveTimeout => EnvironmentConfig.receiveTimeout; static int get receiveTimeout => EnvironmentConfig.receiveTimeout;
static int get sendTimeout => EnvironmentConfig.sendTimeout; static int get sendTimeout => EnvironmentConfig.sendTimeout;
// Retry configurations // Retry configurations (environment-specific)
static int get maxRetries => EnvironmentConfig.maxRetries; static int get maxRetries => EnvironmentConfig.maxRetries;
static Duration get retryDelay => EnvironmentConfig.retryDelay; static Duration get retryDelay => EnvironmentConfig.retryDelay;
@@ -28,21 +28,19 @@ class ApiConstants {
static const String bearerPrefix = 'Bearer'; static const String bearerPrefix = 'Bearer';
static const String apiKeyHeaderKey = 'X-API-Key'; static const String apiKeyHeaderKey = 'X-API-Key';
// Authentication endpoints // Authentication endpoints (from environment config)
static String get authEndpoint => EnvironmentConfig.authEndpoint; static String get authEndpoint => EnvironmentConfig.authEndpoint;
static String get loginEndpoint => EnvironmentConfig.loginEndpoint; static String get loginEndpoint => EnvironmentConfig.loginEndpoint;
static String get registerEndpoint => EnvironmentConfig.registerEndpoint; static String get registerEndpoint => EnvironmentConfig.registerEndpoint;
static String get refreshEndpoint => EnvironmentConfig.refreshEndpoint; static String get refreshEndpoint => EnvironmentConfig.refreshEndpoint;
static String get logoutEndpoint => EnvironmentConfig.logoutEndpoint; static String get logoutEndpoint => EnvironmentConfig.logoutEndpoint;
static String get resetPasswordEndpoint => EnvironmentConfig.resetPasswordEndpoint; static const String userEndpoint = '/user';
static String get changePasswordEndpoint => EnvironmentConfig.changePasswordEndpoint; static const String profileEndpoint = '$userEndpoint/profile';
static String get verifyEmailEndpoint => EnvironmentConfig.verifyEmailEndpoint;
// User endpoints // Example service endpoints (for demonstration)
static String get userEndpoint => EnvironmentConfig.userEndpoint; static const String todosEndpoint = '/todos';
static String get profileEndpoint => EnvironmentConfig.profileEndpoint; static const String postsEndpoint = '/posts';
static String get updateProfileEndpoint => EnvironmentConfig.updateProfileEndpoint; static const String usersEndpoint = '/users';
static String get deleteAccountEndpoint => EnvironmentConfig.deleteAccountEndpoint;
// Cache configurations // Cache configurations
static const Duration cacheMaxAge = Duration(minutes: 5); static const Duration cacheMaxAge = Duration(minutes: 5);
@@ -68,4 +66,8 @@ class ApiConstants {
static bool get enableLogging => EnvironmentConfig.enableLogging; static bool get enableLogging => EnvironmentConfig.enableLogging;
static bool get enableCertificatePinning => EnvironmentConfig.enableCertificatePinning; static bool get enableCertificatePinning => EnvironmentConfig.enableCertificatePinning;
static bool get enableDetailedLogging => EnvironmentConfig.enableDetailedLogging; static bool get enableDetailedLogging => EnvironmentConfig.enableDetailedLogging;
// API rate limiting
static const int maxRequestsPerMinute = 100;
static const Duration rateLimitWindow = Duration(minutes: 1);
} }

View File

@@ -394,9 +394,9 @@ class ApiConnectivityTest extends _$ApiConnectivityTest {
'message': 'Configuration loaded successfully', 'message': 'Configuration loaded successfully',
'endpoints': { 'endpoints': {
'login': EnvironmentConfig.loginUrl, 'login': EnvironmentConfig.loginUrl,
// 'register': EnvironmentConfig.registerUrl, 'register': EnvironmentConfig.registerUrl,
// 'refresh': EnvironmentConfig.refreshUrl, 'refresh': EnvironmentConfig.refreshUrl,
// 'logout': EnvironmentConfig.logoutUrl, 'logout': EnvironmentConfig.logoutUrl,
}, },
'settings': { 'settings': {
'connectTimeout': EnvironmentConfig.connectTimeout, 'connectTimeout': EnvironmentConfig.connectTimeout,

View File

@@ -216,7 +216,7 @@ final errorTrackerProvider = AutoDisposeNotifierProvider<ErrorTracker,
typedef _$ErrorTracker = AutoDisposeNotifier<List<Map<String, dynamic>>>; typedef _$ErrorTracker = AutoDisposeNotifier<List<Map<String, dynamic>>>;
String _$apiConnectivityTestHash() => String _$apiConnectivityTestHash() =>
r'af903de0fec684ef6c701190dfca2a25f97a9392'; r'19c63d75d09ad8f95452afb1a409528fcdd5cbaa';
/// API connectivity test provider /// API connectivity test provider
/// ///

View File

@@ -1,7 +1,10 @@
import 'package:base_flutter/features/lesson/lesson_screen.dart';
import 'package:base_flutter/features/loading_lesson/loading_lesson_screen.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import '../../features/home/models.dart';
import 'route_names.dart'; import 'route_names.dart';
import 'route_paths.dart'; import 'route_paths.dart';
import 'route_guards.dart'; import 'route_guards.dart';
@@ -27,11 +30,39 @@ final routerProvider = Provider<GoRouter>((ref) {
path: RoutePaths.home, path: RoutePaths.home,
name: RouteNames.home, name: RouteNames.home,
pageBuilder: (context, state) => _buildPageWithTransition( pageBuilder: (context, state) => _buildPageWithTransition(
child: const HomePage(), child: const LevelMapScreen(),
state: state, state: state,
), ),
), ),
GoRoute(
path: RoutePaths.lesson,
name: RouteNames.lesson,
pageBuilder: (context, state) => _buildPageWithTransition(
child: const LoadingLessonScreen(),
state: state,
),
routes: [
GoRoute(
path: 'test',
name: 'test',
pageBuilder: (context, state) {
final lessonResponse = state.extra as LessonResponse?;
if (lessonResponse == null) {
return _buildPageWithTransition(
child: const _PlaceholderPage(title: 'No lesson data provided'),
state: state,
);
}
return _buildPageWithTransition(
child: LessonScreen(lessonResponse: lessonResponse),
state: state,
);
},
),
]
),
// Settings routes with nested navigation // Settings routes with nested navigation
GoRoute( GoRoute(
path: RoutePaths.settings, path: RoutePaths.settings,
@@ -128,7 +159,7 @@ final routerProvider = Provider<GoRouter>((ref) {
path: RoutePaths.todos, path: RoutePaths.todos,
name: RouteNames.todos, name: RouteNames.todos,
pageBuilder: (context, state) => _buildPageWithTransition( pageBuilder: (context, state) => _buildPageWithTransition(
child: const TodoScreen(), // Using existing TodoScreen child: const HomeScreen(), // Using existing TodoScreen
state: state, state: state,
), ),
routes: [ routes: [

View File

@@ -7,6 +7,7 @@ class RouteNames {
static const String settings = 'settings'; static const String settings = 'settings';
static const String profile = 'profile'; static const String profile = 'profile';
static const String about = 'about'; static const String about = 'about';
static const String lesson = 'lesson';
// Auth routes // Auth routes
static const String login = 'login'; static const String login = 'login';

View File

@@ -7,6 +7,7 @@ class RoutePaths {
static const String settings = '/settings'; static const String settings = '/settings';
static const String profile = '/profile'; static const String profile = '/profile';
static const String about = '/about'; static const String about = '/about';
static const String lesson = '/lesson';
// Auth routes // Auth routes
static const String login = '/auth/login'; static const String login = '/auth/login';

View File

@@ -16,11 +16,8 @@ class AppTheme {
useMaterial3: true, useMaterial3: true,
colorScheme: AppColors.lightScheme, colorScheme: AppColors.lightScheme,
// Typography - Apply theme colors to text styles // Typography
textTheme: AppTypography.textTheme.apply( textTheme: AppTypography.textTheme,
bodyColor: AppColors.lightScheme.onSurface,
displayColor: AppColors.lightScheme.onSurface,
),
// App bar theme // App bar theme
appBarTheme: _lightAppBarTheme, appBarTheme: _lightAppBarTheme,
@@ -43,7 +40,7 @@ class AppTheme {
floatingActionButtonTheme: _lightFabTheme, floatingActionButtonTheme: _lightFabTheme,
// Input field themes // Input field themes
inputDecorationTheme: _getInputDecorationTheme(AppColors.lightScheme), inputDecorationTheme: _inputDecorationTheme,
// Other component themes // Other component themes
bottomNavigationBarTheme: _lightBottomNavTheme, bottomNavigationBarTheme: _lightBottomNavTheme,
@@ -55,18 +52,14 @@ class AppTheme {
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: AppSpacing.dialogRadius, borderRadius: AppSpacing.dialogRadius,
), ),
titleTextStyle: AppTypography.headlineSmall.copyWith( titleTextStyle: AppTypography.headlineSmall,
color: AppColors.lightScheme.onSurface, contentTextStyle: AppTypography.bodyMedium,
),
contentTextStyle: AppTypography.bodyMedium.copyWith(
color: AppColors.lightScheme.onSurfaceVariant,
),
), ),
bottomSheetTheme: _bottomSheetTheme, bottomSheetTheme: _bottomSheetTheme,
snackBarTheme: _getSnackBarTheme(AppColors.lightScheme), snackBarTheme: _snackBarTheme,
chipTheme: _lightChipTheme, chipTheme: _lightChipTheme,
dividerTheme: _dividerTheme, dividerTheme: _dividerTheme,
listTileTheme: _getListTileTheme(AppColors.lightScheme), listTileTheme: _listTileTheme,
switchTheme: _lightSwitchTheme, switchTheme: _lightSwitchTheme,
checkboxTheme: _lightCheckboxTheme, checkboxTheme: _lightCheckboxTheme,
radioTheme: _lightRadioTheme, radioTheme: _lightRadioTheme,
@@ -99,11 +92,8 @@ class AppTheme {
useMaterial3: true, useMaterial3: true,
colorScheme: AppColors.darkScheme, colorScheme: AppColors.darkScheme,
// Typography - Apply theme colors to text styles // Typography
textTheme: AppTypography.textTheme.apply( textTheme: AppTypography.textTheme,
bodyColor: AppColors.darkScheme.onSurface,
displayColor: AppColors.darkScheme.onSurface,
),
// App bar theme // App bar theme
appBarTheme: _darkAppBarTheme, appBarTheme: _darkAppBarTheme,
@@ -126,7 +116,7 @@ class AppTheme {
floatingActionButtonTheme: _darkFabTheme, floatingActionButtonTheme: _darkFabTheme,
// Input field themes // Input field themes
inputDecorationTheme: _getInputDecorationTheme(AppColors.darkScheme), inputDecorationTheme: _inputDecorationTheme,
// Other component themes // Other component themes
bottomNavigationBarTheme: _darkBottomNavTheme, bottomNavigationBarTheme: _darkBottomNavTheme,
@@ -138,18 +128,14 @@ class AppTheme {
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: AppSpacing.dialogRadius, borderRadius: AppSpacing.dialogRadius,
), ),
titleTextStyle: AppTypography.headlineSmall.copyWith( titleTextStyle: AppTypography.headlineSmall,
color: AppColors.darkScheme.onSurface, contentTextStyle: AppTypography.bodyMedium,
),
contentTextStyle: AppTypography.bodyMedium.copyWith(
color: AppColors.darkScheme.onSurfaceVariant,
),
), ),
bottomSheetTheme: _bottomSheetTheme, bottomSheetTheme: _bottomSheetTheme,
snackBarTheme: _getSnackBarTheme(AppColors.darkScheme), snackBarTheme: _snackBarTheme,
chipTheme: _darkChipTheme, chipTheme: _darkChipTheme,
dividerTheme: _dividerTheme, dividerTheme: _dividerTheme,
listTileTheme: _getListTileTheme(AppColors.darkScheme), listTileTheme: _listTileTheme,
switchTheme: _darkSwitchTheme, switchTheme: _darkSwitchTheme,
checkboxTheme: _darkCheckboxTheme, checkboxTheme: _darkCheckboxTheme,
radioTheme: _darkRadioTheme, radioTheme: _darkRadioTheme,
@@ -299,7 +285,7 @@ class AppTheme {
), ),
); );
static InputDecorationTheme _getInputDecorationTheme(ColorScheme colorScheme) => InputDecorationTheme( static InputDecorationTheme get _inputDecorationTheme => InputDecorationTheme(
filled: true, filled: true,
contentPadding: const EdgeInsets.all(AppSpacing.fieldPadding), contentPadding: const EdgeInsets.all(AppSpacing.fieldPadding),
border: OutlineInputBorder( border: OutlineInputBorder(
@@ -322,65 +308,35 @@ class AppTheme {
borderRadius: AppSpacing.fieldRadius, borderRadius: AppSpacing.fieldRadius,
borderSide: const BorderSide(width: AppSpacing.borderWidthThick), borderSide: const BorderSide(width: AppSpacing.borderWidthThick),
), ),
errorStyle: AppTypography.errorText.copyWith(color: colorScheme.error), errorStyle: AppTypography.errorText,
hintStyle: AppTypography.hintText.copyWith(color: colorScheme.onSurfaceVariant), hintStyle: AppTypography.hintText,
labelStyle: AppTypography.bodyMedium.copyWith(color: colorScheme.onSurfaceVariant), labelStyle: AppTypography.bodyMedium,
); );
static BottomNavigationBarThemeData get _lightBottomNavTheme => BottomNavigationBarThemeData( static BottomNavigationBarThemeData get _lightBottomNavTheme => const BottomNavigationBarThemeData(
type: BottomNavigationBarType.fixed, type: BottomNavigationBarType.fixed,
elevation: AppSpacing.elevationMedium, elevation: AppSpacing.elevationMedium,
selectedLabelStyle: AppTypography.labelSmall.copyWith( selectedLabelStyle: AppTypography.labelSmall,
color: AppColors.lightScheme.primary, unselectedLabelStyle: AppTypography.labelSmall,
),
unselectedLabelStyle: AppTypography.labelSmall.copyWith(
color: AppColors.lightScheme.onSurfaceVariant,
),
); );
static BottomNavigationBarThemeData get _darkBottomNavTheme => BottomNavigationBarThemeData( static BottomNavigationBarThemeData get _darkBottomNavTheme => const BottomNavigationBarThemeData(
type: BottomNavigationBarType.fixed, type: BottomNavigationBarType.fixed,
elevation: AppSpacing.elevationMedium, elevation: AppSpacing.elevationMedium,
selectedLabelStyle: AppTypography.labelSmall.copyWith( selectedLabelStyle: AppTypography.labelSmall,
color: AppColors.darkScheme.primary, unselectedLabelStyle: AppTypography.labelSmall,
),
unselectedLabelStyle: AppTypography.labelSmall.copyWith(
color: AppColors.darkScheme.onSurfaceVariant,
),
); );
static NavigationBarThemeData get _lightNavigationBarTheme => NavigationBarThemeData( static NavigationBarThemeData get _lightNavigationBarTheme => NavigationBarThemeData(
height: 80, height: 80,
elevation: AppSpacing.elevationMedium, elevation: AppSpacing.elevationMedium,
labelTextStyle: WidgetStateProperty.resolveWith<TextStyle?>( labelTextStyle: WidgetStateProperty.all(AppTypography.labelSmall),
(Set<WidgetState> states) {
if (states.contains(WidgetState.selected)) {
return AppTypography.labelSmall.copyWith(
color: AppColors.lightScheme.primary,
);
}
return AppTypography.labelSmall.copyWith(
color: AppColors.lightScheme.onSurfaceVariant,
);
},
),
); );
static NavigationBarThemeData get _darkNavigationBarTheme => NavigationBarThemeData( static NavigationBarThemeData get _darkNavigationBarTheme => NavigationBarThemeData(
height: 80, height: 80,
elevation: AppSpacing.elevationMedium, elevation: AppSpacing.elevationMedium,
labelTextStyle: WidgetStateProperty.resolveWith<TextStyle?>( labelTextStyle: WidgetStateProperty.all(AppTypography.labelSmall),
(Set<WidgetState> states) {
if (states.contains(WidgetState.selected)) {
return AppTypography.labelSmall.copyWith(
color: AppColors.darkScheme.primary,
);
}
return AppTypography.labelSmall.copyWith(
color: AppColors.darkScheme.onSurfaceVariant,
);
},
),
); );
static NavigationRailThemeData get _lightNavigationRailTheme => const NavigationRailThemeData( static NavigationRailThemeData get _lightNavigationRailTheme => const NavigationRailThemeData(
@@ -413,15 +369,13 @@ class AppTheme {
), ),
); );
static SnackBarThemeData _getSnackBarTheme(ColorScheme colorScheme) => SnackBarThemeData( static SnackBarThemeData get _snackBarTheme => SnackBarThemeData(
elevation: AppSpacing.elevationMedium, elevation: AppSpacing.elevationMedium,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: AppSpacing.radiusSM, borderRadius: AppSpacing.radiusSM,
), ),
behavior: SnackBarBehavior.floating, behavior: SnackBarBehavior.floating,
contentTextStyle: AppTypography.bodyMedium.copyWith( contentTextStyle: AppTypography.bodyMedium,
color: colorScheme.onInverseSurface,
),
); );
static ChipThemeData get _lightChipTheme => ChipThemeData( static ChipThemeData get _lightChipTheme => ChipThemeData(
@@ -429,9 +383,7 @@ class AppTheme {
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: AppSpacing.radiusSM, borderRadius: AppSpacing.radiusSM,
), ),
labelStyle: AppTypography.labelMedium.copyWith( labelStyle: AppTypography.labelMedium,
color: AppColors.lightScheme.onSurfaceVariant,
),
); );
static ChipThemeData get _darkChipTheme => ChipThemeData( static ChipThemeData get _darkChipTheme => ChipThemeData(
@@ -439,9 +391,7 @@ class AppTheme {
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: AppSpacing.radiusSM, borderRadius: AppSpacing.radiusSM,
), ),
labelStyle: AppTypography.labelMedium.copyWith( labelStyle: AppTypography.labelMedium,
color: AppColors.darkScheme.onSurfaceVariant,
),
); );
static const DividerThemeData _dividerTheme = DividerThemeData( static const DividerThemeData _dividerTheme = DividerThemeData(
@@ -449,17 +399,13 @@ class AppTheme {
space: AppSpacing.dividerSpacing, space: AppSpacing.dividerSpacing,
); );
static ListTileThemeData _getListTileTheme(ColorScheme colorScheme) => ListTileThemeData( static ListTileThemeData get _listTileTheme => const ListTileThemeData(
contentPadding: const EdgeInsets.symmetric( contentPadding: EdgeInsets.symmetric(
horizontal: AppSpacing.listItemPadding, horizontal: AppSpacing.listItemPadding,
vertical: AppSpacing.listItemMargin, vertical: AppSpacing.listItemMargin,
), ),
titleTextStyle: AppTypography.titleMedium.copyWith( titleTextStyle: AppTypography.titleMedium,
color: colorScheme.onSurface, subtitleTextStyle: AppTypography.bodyMedium,
),
subtitleTextStyle: AppTypography.bodyMedium.copyWith(
color: colorScheme.onSurfaceVariant,
),
); );
static SwitchThemeData get _lightSwitchTheme => SwitchThemeData( static SwitchThemeData get _lightSwitchTheme => SwitchThemeData(
@@ -517,11 +463,7 @@ class AppTheme {
/// Create responsive theme based on screen size /// Create responsive theme based on screen size
static ThemeData responsiveTheme(BuildContext context, {required bool isDark}) { static ThemeData responsiveTheme(BuildContext context, {required bool isDark}) {
final baseTheme = isDark ? darkTheme : lightTheme; final baseTheme = isDark ? darkTheme : lightTheme;
final colorScheme = isDark ? AppColors.darkScheme : AppColors.lightScheme; final responsiveTextTheme = AppTypography.responsiveTextTheme(context);
final responsiveTextTheme = AppTypography.responsiveTextTheme(context).apply(
bodyColor: colorScheme.onSurface,
displayColor: colorScheme.onSurface,
);
return baseTheme.copyWith( return baseTheme.copyWith(
textTheme: responsiveTextTheme, textTheme: responsiveTextTheme,

View File

@@ -284,7 +284,7 @@ class _LoginPageState extends ConsumerState<LoginPage>
) { ) {
return AnimatedContainer( return AnimatedContainer(
duration: AppSpacing.animationNormal, duration: AppSpacing.animationNormal,
height: isKeyboardVisible ? 120 : 190, height: isKeyboardVisible ? 120 : 180,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [

View File

@@ -0,0 +1,79 @@
class LessonResponse {
final String image; // base64 string
final String response;
final WidgetData widget;
LessonResponse({
required this.image,
required this.response,
required this.widget,
});
factory LessonResponse.fromJson(Map<String, dynamic> json) {
return LessonResponse(
image: json['image'] as String,
response: json['response'] as String,
widget: WidgetData.fromJson(json['widget']),
);
}
Map<String, dynamic> toJson() {
return {
'image': image,
'response': response,
'widget': widget.toJson(),
};
}
}
class WidgetData {
final TapWidget tapToRecordWidget;
final TapWidget tapToSpeechWidget;
WidgetData({
required this.tapToRecordWidget,
required this.tapToSpeechWidget,
});
factory WidgetData.fromJson(Map<String, dynamic> json) {
return WidgetData(
tapToRecordWidget:
TapWidget.fromJson(json['tap_to_record_widget']),
tapToSpeechWidget:
TapWidget.fromJson(json['tap_to_speech_widget']),
);
}
Map<String, dynamic> toJson() {
return {
'tap_to_record_widget': tapToRecordWidget.toJson(),
'tap_to_speech_widget': tapToSpeechWidget.toJson(),
};
}
}
class TapWidget {
final String content;
final String position;
TapWidget({
required this.content,
required this.position,
});
factory TapWidget.fromJson(Map<String, dynamic> json) {
return TapWidget(
content: json['content'] as String,
position: json['position'] as String,
);
}
Map<String, dynamic> toJson() {
return {
'content': content,
'position': position,
};
}
}

View File

@@ -1,3 +1,5 @@
import 'dart:math' as math;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
@@ -6,506 +8,505 @@ import '../../../../core/routing/route_guards.dart';
import '../../../../shared/presentation/providers/app_providers.dart'; import '../../../../shared/presentation/providers/app_providers.dart';
/// Home page with navigation to different features /// Home page with navigation to different features
class HomePage extends ConsumerWidget { class LevelMapScreen extends StatefulWidget {
const HomePage({super.key}); const LevelMapScreen({super.key});
@override @override
Widget build(BuildContext context, WidgetRef ref) { State<LevelMapScreen> createState() => _LevelMapScreenState();
final authState = ref.watch(authStateProvider); }
final themeMode = ref.watch(themeModeProvider);
class _LevelMapScreenState extends State<LevelMapScreen> {
final ScrollController _scroll = ScrollController();
// ---- Dynamic level data (change these) ----
final int totalLevels = 60; // total levels you want to show
final int currentLevelIndex = 4; // 0-based index of current level
// ---- Layout knobs (tweak to taste) ----
static const double kNodeSpacing = 220; // px along the path between bubbles
static const double kStartOffset = 140; // first bubble offset from path start
static const double kVerticalStep = 270; // vertical descent per circle loop
// The scrollable map height is finite and derived from how many levels we show.
double get mapHeight {
return _calculateRequiredHeight(
totalLevels: totalLevels,
nodeSpacing: kNodeSpacing,
startOffset: kStartOffset,
);
}
/// Calculate the actual vertical height needed for circular path
double _calculateRequiredHeight({
required int totalLevels,
required double nodeSpacing,
required double startOffset,
}) {
// Path parameters (must match _buildCircularPath)
const double baseRadius = 0.32; // percentage of width
const double topPadding = 100.0;
const double bottomPadding = 100.0;
// Estimate circle circumference (approximation for cubic bezier circle)
final screenWidth = MediaQuery.of(context).size.width;
final radiusInPixels = screenWidth * baseRadius;
final approximateCircleLength = 2 * math.pi * radiusInPixels;
// Total path length needed for all nodes
final totalPathLength = startOffset + (totalLevels - 1) * nodeSpacing;
// Calculate how many circles we need
final numberOfCircles = (totalPathLength / approximateCircleLength).ceil();
// Calculate actual vertical height
final contentHeight = numberOfCircles * kVerticalStep;
final totalHeight = topPadding + contentHeight + bottomPadding;
return math.max(1200, totalHeight);
}
double? _currentLevelY; // used to auto-scroll near the current level
@override
void initState() {
super.initState();
// Auto-scroll after first layout
WidgetsBinding.instance.addPostFrameCallback((_) {
final y = _currentLevelY ?? 0;
final screenH = MediaQuery.of(context).size.height;
final target = (y - screenH * 0.45).clamp(0.0, mapHeight);
_scroll.animateTo(
target,
duration: const Duration(milliseconds: 600),
curve: Curves.easeOutCubic,
);
});
}
@override
void dispose() {
_scroll.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( backgroundColor: const Color(0xFFFFB43E), // warm island background
title: const Text('Base Flutter App'), body: SafeArea(
actions: [ child: Column(
// Theme toggle button children: [
IconButton( _buildHeader(),
onPressed: () { Expanded(
ref.read(themeModeProvider.notifier).toggleTheme(); child: LayoutBuilder(
builder: (ctx, c) {
return SingleChildScrollView(
controller: _scroll,
child: SizedBox(
height: mapHeight, // <-- finite height
width: c.maxWidth,
child: LevelMap(
totalLevels: totalLevels,
currentIndex: currentLevelIndex,
nodeSpacing: kNodeSpacing,
startOffsetOnPath: kStartOffset,
verticalStep: kVerticalStep,
showFinishAtEnd: true,
onCurrentLevelPositionResolved: (dy) {
_currentLevelY = dy;
},
),
),
);
},
),
),
_buildBottomNav(),
],
),
),
);
}
Widget _buildHeader() => Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 12),
child: Row(
children: [
IconButton(onPressed: () {}, icon: const Icon(Icons.arrow_back)),
const Expanded(
child: Text(
'Kho báu đảo hoang',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
),
IconButton(onPressed: () {}, icon: const Icon(Icons.refresh)),
],
),
);
Widget _buildBottomNav() => Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(20), topRight: Radius.circular(20)),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.08),
blurRadius: 12,
offset: const Offset(0, -2),
)
],
),
child: SafeArea(
top: false,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: const [
_Nav(icon: Icons.home, label: 'Trang chủ'),
_Nav(icon: Icons.location_on, label: 'Khám phá', active: true),
_Nav(icon: Icons.bar_chart, label: 'Xếp hạng'),
_Nav(icon: Icons.people, label: 'Kết nối'),
_Nav(icon: Icons.person, label: 'Cá nhân'),
],
),
),
),
);
}
class _Nav extends StatelessWidget {
final IconData icon;
final String label;
final bool active;
const _Nav({required this.icon, required this.label, this.active = false, super.key});
@override
Widget build(BuildContext context) {
return Column(mainAxisSize: MainAxisSize.min, children: [
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: active ? Colors.orange : Colors.transparent,
borderRadius: BorderRadius.circular(12),
),
child: Icon(icon, color: active ? Colors.white : Colors.grey)),
const SizedBox(height: 4),
Text(
label,
style: TextStyle(
fontSize: 12,
color: active ? Colors.orange : Colors.grey,
fontWeight: active ? FontWeight.bold : FontWeight.normal,
),
),
]);
}
}
/// Draws the path and positions dynamic level nodes **along the path**.
class LevelMap extends StatelessWidget {
final int totalLevels;
final int currentIndex;
final double nodeSpacing;
final double startOffsetOnPath;
final double verticalStep;
final bool showFinishAtEnd;
final ValueChanged<double>? onCurrentLevelPositionResolved;
const LevelMap({
super.key,
required this.totalLevels,
required this.currentIndex,
required this.nodeSpacing,
required this.startOffsetOnPath,
required this.verticalStep,
this.showFinishAtEnd = false,
this.onCurrentLevelPositionResolved,
});
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (ctx, c) {
final size = Size(c.maxWidth, c.maxHeight);
// Build a circular/spiral path that fills this finite canvas.
final path = _buildCircularPath(size, verticalStep);
// Measure the path
final metrics = path.computeMetrics().toList();
if (metrics.isEmpty) return const SizedBox.shrink();
final metric = metrics.first; // single contour
final totalLen = metric.length;
// Required length to host all visible levels
final requiredLen =
startOffsetOnPath + (math.max(1, totalLevels) - 1) * nodeSpacing;
// Clamp to available path length
final effectiveLen = requiredLen.clamp(0, totalLen - 1);
// Compute bubble positions
final nodes = <Widget>[];
const bubbleRadius = 28.0; // 56x56
const eps = 0.001;
double d = startOffsetOnPath;
Offset? lastNodePosition; // Track last node position for finish flag
for (int i = 0; i < totalLevels; i++) {
final clamped = d.clamp(0, totalLen - eps);
final tan = metric.getTangentForOffset(clamped.toDouble())!;
final pos = tan.position;
// Store last node position
if (i == totalLevels - 1) {
lastNodePosition = pos;
}
nodes.add(Positioned(
left: pos.dx - bubbleRadius,
top: pos.dy - bubbleRadius,
child: LevelNode(
level: i + 1,
isCompleted: i < currentIndex,
isCurrent: i == currentIndex,
isLocked: i > currentIndex,
onTap: i > currentIndex ? null : () {
debugPrint('Level ${i + 1} tapped');
context.pushNamed('lesson');
}, },
icon: Icon(
themeMode == ThemeMode.dark
? Icons.light_mode
: themeMode == ThemeMode.light
? Icons.dark_mode
: Icons.brightness_auto,
),
tooltip: 'Toggle theme',
), ),
// Settings button ));
IconButton(
onPressed: () => context.push(RoutePaths.settings),
icon: const Icon(Icons.settings),
tooltip: 'Settings',
),
],
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Welcome section
_WelcomeCard(authState: authState),
const SizedBox(height: 24), d += nodeSpacing;
if (d > totalLen - eps) break; // stop when path ends
}
// Quick actions section // Report current Y for auto-scroll
Text( WidgetsBinding.instance.addPostFrameCallback((_) {
'Quick Actions', if (onCurrentLevelPositionResolved != null &&
style: Theme.of(context).textTheme.headlineSmall?.copyWith( currentIndex >= 0 &&
fontWeight: FontWeight.bold, currentIndex < nodes.length) {
), final clamped = (startOffsetOnPath + currentIndex * nodeSpacing)
), .clamp(0, totalLen - eps);
const SizedBox(height: 16), final tan = metric.getTangentForOffset(clamped.toDouble())!;
onCurrentLevelPositionResolved!(tan.position.dy);
}
});
_QuickActionsGrid(), // Optional finish flag at last level position
if (showFinishAtEnd && lastNodePosition != null) {
nodes.add(Positioned(
left: lastNodePosition.dx - 18,
top: lastNodePosition.dy - 60,
child: const Icon(Icons.flag, color: Colors.red, size: 36),
));
}
const SizedBox(height: 24), return Stack(
clipBehavior: Clip.none,
// Features section
Text(
'Features',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
_FeaturesGrid(),
const SizedBox(height: 24),
// Recent activity section
_RecentActivityCard(),
],
),
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () => context.push(RoutePaths.addTodo),
icon: const Icon(Icons.add),
label: const Text('Add Todo'),
),
);
}
}
class _WelcomeCard extends StatelessWidget {
final AuthState authState;
const _WelcomeCard({
required this.authState,
});
@override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
CircleAvatar(
radius: 24,
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
child: Icon(
Icons.person,
color: Theme.of(context).colorScheme.onPrimaryContainer,
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
authState == AuthState.authenticated
? 'Welcome back!'
: 'Welcome!',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
),
),
Text(
authState == AuthState.authenticated
? 'Ready to be productive today?'
: 'Get started with the base Flutter app.',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
],
),
),
],
),
if (authState == AuthState.unauthenticated) ...[
const SizedBox(height: 16),
Row(
children: [
Expanded(
child: OutlinedButton(
onPressed: () => context.push(RoutePaths.login),
child: const Text('Login'),
),
),
const SizedBox(width: 12),
Expanded(
child: FilledButton(
onPressed: () => context.push(RoutePaths.register),
child: const Text('Register'),
),
),
],
),
],
],
),
),
);
}
}
class _QuickActionsGrid extends StatelessWidget {
@override
Widget build(BuildContext context) {
final quickActions = [
_QuickAction(
icon: Icons.add_task,
title: 'Add Todo',
subtitle: 'Create a new task',
onTap: () => context.push(RoutePaths.addTodo),
),
_QuickAction(
icon: Icons.list,
title: 'View Todos',
subtitle: 'See all tasks',
onTap: () => context.push(RoutePaths.todos),
),
_QuickAction(
icon: Icons.settings,
title: 'Settings',
subtitle: 'App preferences',
onTap: () => context.push(RoutePaths.settings),
),
_QuickAction(
icon: Icons.info,
title: 'About',
subtitle: 'App information',
onTap: () => context.push(RoutePaths.about),
),
];
return GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 12,
mainAxisSpacing: 12,
childAspectRatio: 1.2,
),
itemCount: quickActions.length,
itemBuilder: (context, index) {
return _QuickActionCard(action: quickActions[index]);
},
);
}
}
class _FeaturesGrid extends StatelessWidget {
@override
Widget build(BuildContext context) {
final features = [
_Feature(
icon: Icons.check_circle_outline,
title: 'Todo Management',
description: 'Create, edit, and track your tasks efficiently.',
color: Colors.blue,
onTap: () => context.push(RoutePaths.todos),
),
_Feature(
icon: Icons.palette,
title: 'Theming',
description: 'Switch between light, dark, and system themes.',
color: Colors.purple,
onTap: () => context.push(RoutePaths.settingsTheme),
),
_Feature(
icon: Icons.storage,
title: 'Local Storage',
description: 'Hive database integration for offline support.',
color: Colors.orange,
onTap: () => context.push(RoutePaths.settings),
),
_Feature(
icon: Icons.security,
title: 'Secure Storage',
description: 'Protected storage for sensitive data.',
color: Colors.green,
onTap: () => context.push(RoutePaths.settingsPrivacy),
),
];
return GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 12,
mainAxisSpacing: 12,
childAspectRatio: 0.8,
),
itemCount: features.length,
itemBuilder: (context, index) {
return _FeatureCard(feature: features[index]);
},
);
}
}
class _RecentActivityCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Recent Activity',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
TextButton(
onPressed: () => context.push(RoutePaths.todos),
child: const Text('View All'),
),
],
),
const SizedBox(height: 12),
_ActivityItem(
icon: Icons.add_task,
title: 'Welcome to Base Flutter App',
subtitle: 'Your journey starts here',
time: 'Just now',
),
_ActivityItem(
icon: Icons.info,
title: 'App initialized',
subtitle: 'Database and services ready',
time: 'A few seconds ago',
),
],
),
),
);
}
}
class _QuickActionCard extends StatelessWidget {
final _QuickAction action;
const _QuickActionCard({
required this.action,
});
@override
Widget build(BuildContext context) {
return Card(
child: InkWell(
onTap: action.onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
action.icon,
size: 32,
color: Theme.of(context).colorScheme.primary,
),
const SizedBox(height: 8),
Text(
action.title,
style: Theme.of(context).textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 4),
Text(
action.subtitle,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
),
),
);
}
}
class _FeatureCard extends StatelessWidget {
final _Feature feature;
const _FeatureCard({
required this.feature,
});
@override
Widget build(BuildContext context) {
return Card(
child: InkWell(
onTap: feature.onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: feature.color.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child: Icon(
feature.icon,
color: feature.color,
size: 24,
),
),
const SizedBox(height: 12),
Text(
feature.title,
style: Theme.of(context).textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.bold,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Expanded(
child: Text(
feature.description,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
),
);
}
}
class _ActivityItem extends StatelessWidget {
final IconData icon;
final String title;
final String subtitle;
final String time;
const _ActivityItem({
required this.icon,
required this.title,
required this.subtitle,
required this.time,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
children: [ children: [
Container( // Cute background bits (optional)
padding: const EdgeInsets.all(8), Positioned.fill(child: CustomPaint(painter: DecorationPainter())),
decoration: BoxDecoration( // Sandy road
color: Theme.of(context).colorScheme.primaryContainer.withOpacity(0.5), Positioned.fill(child: CustomPaint(painter: SandPathPainter(path))),
borderRadius: BorderRadius.circular(8), // Bubbles
), ...nodes,
child: Icon(
icon,
size: 16,
color: Theme.of(context).colorScheme.onPrimaryContainer,
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w500,
),
),
Text(
subtitle,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
),
],
),
),
Text(
time,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.5),
),
),
], ],
), );
); });
}
/// Creates a circular/spiral path that goes in circles while progressing downward
Path _buildCircularPath(Size size, double verticalStep) {
final path = Path();
final centerX = size.width * 0.5;
final baseRadius = size.width * 0.32; // radius of the circular motion
double y = 100;
// Start at top center
path.moveTo(centerX, y);
// Create circular loops going downward
while (y < size.height - 100) {
// Create a full circle using cubic bezier curves (4 curves make a circle)
final startY = y;
// Right curve (0° to 90°)
path.cubicTo(
centerX + baseRadius * 0.55, startY,
centerX + baseRadius, startY + verticalStep * 0.25 - baseRadius * 0.55,
centerX + baseRadius, startY + verticalStep * 0.25,
);
// Bottom curve (90° to 180°)
path.cubicTo(
centerX + baseRadius, startY + verticalStep * 0.25 + baseRadius * 0.55,
centerX + baseRadius * 0.55, startY + verticalStep * 0.5,
centerX, startY + verticalStep * 0.5,
);
// Left curve (180° to 270°)
path.cubicTo(
centerX - baseRadius * 0.55, startY + verticalStep * 0.5,
centerX - baseRadius, startY + verticalStep * 0.75 - baseRadius * 0.55,
centerX - baseRadius, startY + verticalStep * 0.75,
);
// Top curve (270° to 360°)
path.cubicTo(
centerX - baseRadius, startY + verticalStep * 0.75 + baseRadius * 0.55,
centerX - baseRadius * 0.55, startY + verticalStep,
centerX, startY + verticalStep,
);
y += verticalStep;
}
return path;
} }
} }
class _QuickAction { /// Painter for the sand road with subtle depth.
final IconData icon; class SandPathPainter extends CustomPainter {
final String title; final Path path;
final String subtitle; SandPathPainter(this.path);
final VoidCallback onTap;
const _QuickAction({ @override
required this.icon, void paint(Canvas canvas, Size size) {
required this.title, // Glow/soft highlight
required this.subtitle, final glow = Paint()
required this.onTap, ..color = const Color(0x26FFFFFF)
}); ..style = PaintingStyle.stroke
..strokeWidth = 84
..strokeCap = StrokeCap.round
..maskFilter = const MaskFilter.blur(BlurStyle.normal, 10);
canvas.drawPath(path, glow);
// Main sand
final sand = Paint()
..color = const Color(0xFFFFD18C)
..style = PaintingStyle.stroke
..strokeWidth = 64
..strokeCap = StrokeCap.round
..strokeJoin = StrokeJoin.round;
canvas.drawPath(path, sand);
// Inner shade for depth
final inner = Paint()
..color = const Color(0xFFEAB66F)
..style = PaintingStyle.stroke
..strokeWidth = 36
..strokeCap = StrokeCap.round;
canvas.drawPath(path, inner);
}
@override
bool shouldRepaint(covariant SandPathPainter oldDelegate) =>
oldDelegate.path != path;
} }
class _Feature { /// Simple decorative painter (palms/hills placeholders).
final IconData icon; class DecorationPainter extends CustomPainter {
final String title; @override
final String description; void paint(Canvas canvas, Size size) {
final Color color; final palm = Paint()..color = const Color(0xFF66A060);
final VoidCallback onTap; final hill = Paint()..color = const Color(0xFFFFE1A8).withOpacity(.35);
const _Feature({ for (double y = 160; y < size.height; y += 260) {
required this.icon, canvas.drawCircle(Offset(size.width * 0.18, y), 10, palm);
required this.title, canvas.drawCircle(Offset(size.width * 0.82, y + 70), 10, palm);
required this.description, canvas.drawRRect(
required this.color, RRect.fromRectAndRadius(
required this.onTap, Rect.fromCenter(
}); center: Offset(size.width * 0.5, y + 120),
width: 140,
height: 60,
),
const Radius.circular(30),
),
hill,
);
}
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}
class LevelNode extends StatelessWidget {
final int level;
final bool isCompleted;
final bool isCurrent;
final bool isLocked;
final VoidCallback? onTap;
const LevelNode({
super.key,
required this.level,
required this.isCompleted,
required this.isCurrent,
required this.isLocked,
this.onTap,
});
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: isLocked ? null : onTap,
child: Container(
width: 56,
height: 56,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
border: Border.all(
color: isCurrent ? Colors.orange : Colors.white,
width: 4,
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.18),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Center(child: _inner()),
),
);
}
Widget _inner() {
if (isCompleted) {
return const Icon(Icons.check_circle, color: Colors.green, size: 28);
}
if (isLocked) {
return const Icon(Icons.lock, color: Colors.grey, size: 22);
}
if (isCurrent) {
return Container(
width: 44,
height: 44,
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
colors: [Colors.orange.shade300, Colors.orange.shade700],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: const Icon(Icons.play_arrow, color: Colors.white),
);
}
return Text(
'$level',
style: const TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: Colors.orange),
);
}
} }

View File

@@ -0,0 +1,113 @@
import 'dart:convert';
import 'package:base_flutter/features/lesson/record_dialog.dart';
import 'package:record/record.dart';
import 'package:base_flutter/features/home/models.dart';
import 'package:flutter/material.dart';
import 'package:flutter_tts/flutter_tts.dart';
FlutterTts flutterTts = FlutterTts();
enum PositionEnum {
topLeft('top_left'),
topRight('top_right'),
bottomLeft('bottom_left'),
bottomRight('bottom_right');
final String value;
const PositionEnum(this.value);
}
class LessonScreen extends StatefulWidget {
const LessonScreen({super.key, required this.lessonResponse});
final LessonResponse lessonResponse;
@override
State<LessonScreen> createState() => _LessonScreenState();
}
class _LessonScreenState extends State<LessonScreen> {
@override
Widget build(BuildContext context) {
final record = AudioRecorder();
Widget containerText(String text) {
return InkWell(
onTap: () async {
var result = await flutterTts.speak(text);
},
child: Container(
padding: const EdgeInsets.all(8.0),
margin: const EdgeInsets.all(16.0),
width: 300,
height: 120,
color: Colors.black54,
child: Text(text, style: const TextStyle(color: Colors.white, fontSize: 16)),
),
);
}
Widget buildTapToRecordWidget(String position, String content) {
switch (position) {
case 'top_left':
return Align(alignment: Alignment.topLeft, child: containerText(content));
case 'top_right':
return Align(alignment: Alignment.topRight, child: containerText(content));
case 'bottom_left':
return Align(alignment: Alignment.bottomLeft, child: containerText(content));
case 'bottom_right':
return Align(alignment: Alignment.bottomRight, child: containerText(content));
default:
return const SizedBox.shrink();
}
}
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: MemoryImage(base64Decode(widget.lessonResponse.image)),
fit: BoxFit.cover, // Optional: Adjust as needed
),
),
child: Column(
children: [
SizedBox(height: kToolbarHeight,),
Text(widget.lessonResponse.widget.tapToRecordWidget.position),
buildTapToRecordWidget(
widget.lessonResponse.widget.tapToRecordWidget.position,
widget.lessonResponse.widget.tapToRecordWidget.content,
),
Spacer(),
Text(widget.lessonResponse.widget.tapToSpeechWidget.position),
buildTapToRecordWidget(
widget.lessonResponse.widget.tapToSpeechWidget.position,
widget.lessonResponse.widget.tapToSpeechWidget.content,
),
IconButton(
onPressed: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
content: RecordDialog(),
),
);
},
icon: Icon(Icons.mic, size: 48),
),
],
),
),
);
}
}

View File

@@ -0,0 +1,79 @@
import 'package:flutter/material.dart';
import 'package:record/record.dart';
import 'package:audioplayers/audioplayers.dart';
class RecordDialog extends StatefulWidget {
const RecordDialog({super.key});
@override
State<RecordDialog> createState() => _RecordDialogState();
}
class _RecordDialogState extends State<RecordDialog> {
final AudioRecorder _recorder = AudioRecorder();
final AudioPlayer _player = AudioPlayer();
String? _recordedPath;
bool _isRecording = false;
@override
void dispose() {
_recorder.dispose();
_player.dispose();
super.dispose();
}
Future<void> _toggleRecord() async {
if (!_isRecording) {
if (await _recorder.hasPermission()) {
await _recorder.start(const RecordConfig(), path: 'myFile.m4a');
setState(() => _isRecording = true);
}
} else {
final path = await _recorder.stop();
setState(() {
_isRecording = false;
_recordedPath = path;
});
}
}
Future<void> _playRecording() async {
if (_recordedPath != null) {
await _player.play(DeviceFileSource(_recordedPath!));
}
}
@override
Widget build(BuildContext context) {
return SizedBox(
width: 300,
height: 400,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 150),
IconButton(
icon: Icon(_isRecording ? Icons.stop : Icons.mic_none_sharp, size: 96),
onPressed: _toggleRecord,
),
if (_recordedPath != null && !_isRecording)
IconButton(
icon: const Icon(Icons.play_arrow, size: 48),
onPressed: _playRecording,
),
const Spacer(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(onPressed: () => Navigator.pop(context), child: const Text('Close')),
// Add more buttons as needed
],
),
],
),
);
}
}
// Usage in your code:

View File

@@ -0,0 +1,52 @@
import 'package:base_flutter/features/home/models.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
class LoadingLessonScreen extends StatefulWidget {
const LoadingLessonScreen({super.key});
@override
State<LoadingLessonScreen> createState() => _LoadingLessonScreenState();
}
class _LoadingLessonScreenState extends State<LoadingLessonScreen> {
LessonResponse? lessonResponse;
@override
void initState() {
// TODO: implement initState
super.initState();
callDio();
}
void callDio() async {
final dio = Dio();
final response = await dio.get('https://37b530e059dd.ngrok-free.app/');
setState(() {
lessonResponse = LessonResponse.fromJson(response.data);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: lessonResponse == null ? const CircularProgressIndicator() : Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Lesson Title: ${lessonResponse!.response}'),
TextButton(onPressed: () {
context.pushNamed('test', extra: lessonResponse);
}, child: Text('Next')),
],
)
),
);
}
}

View File

@@ -575,32 +575,38 @@ class ThemeSettingsPage extends ConsumerWidget {
body: Column( body: Column(
children: [ children: [
const SizedBox(height: 16), const SizedBox(height: 16),
RadioGroup<ThemeMode>( RadioListTile<ThemeMode>(
title: const Text('Light'),
subtitle: const Text('Use light theme'),
value: ThemeMode.light,
groupValue: themeMode,
onChanged: (value) {
if (value != null) {
ref.read(themeModeProvider.notifier).setThemeMode(value);
}
},
),
RadioListTile<ThemeMode>(
title: const Text('Dark'),
subtitle: const Text('Use dark theme'),
value: ThemeMode.dark,
groupValue: themeMode,
onChanged: (value) {
if (value != null) {
ref.read(themeModeProvider.notifier).setThemeMode(value);
}
},
),
RadioListTile<ThemeMode>(
title: const Text('System'),
subtitle: const Text('Follow system theme'),
value: ThemeMode.system,
groupValue: themeMode, groupValue: themeMode,
onChanged: (value) { onChanged: (value) {
if (value != null) { if (value != null) {
ref.read(themeModeProvider.notifier).setThemeMode(value); ref.read(themeModeProvider.notifier).setThemeMode(value);
} }
}, },
child: Column(
children: [
RadioListTile<ThemeMode>(
title: const Text('Light'),
subtitle: const Text('Use light theme'),
value: ThemeMode.light,
),
RadioListTile<ThemeMode>(
title: const Text('Dark'),
subtitle: const Text('Use dark theme'),
value: ThemeMode.dark,
),
RadioListTile<ThemeMode>(
title: const Text('System'),
subtitle: const Text('Follow system theme'),
value: ThemeMode.system,
),
],
),
), ),
const SizedBox(height: 32), const SizedBox(height: 32),
Padding( Padding(

View File

@@ -1,28 +0,0 @@
import 'package:base_flutter/core/utils/utils.dart';
import '../../../../core/network/dio_client.dart';
import '../../../../core/constants/environment_config.dart';
import '../../../../core/services/api_service.dart';
import '../models/todo_model.dart';
abstract class TodoRemoteDataSource {
Future<List<TodoModel>> getTodos();
}
class TodoRemoteDataSourceImpl extends BaseApiService
implements TodoRemoteDataSource {
TodoRemoteDataSourceImpl({required DioClient dioClient}) : super(dioClient);
@override
Future<List<TodoModel>> getTodos() async {
final response = await dioClient.get(EnvironmentConfig.todosEndpoint);
if (response.data is List) {
final List<dynamic> todosJson = response.data as List<dynamic>;
return todosJson
.map((json) => TodoModel.fromJson(json as DataMap))
.toList();
} else {
throw Exception('Expected List but got ${response.data.runtimeType}');
}
}
}

View File

@@ -1,46 +0,0 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import '../../domain/entities/todo.dart';
part 'todo_model.freezed.dart';
part 'todo_model.g.dart';
@freezed
class TodoModel with _$TodoModel {
const factory TodoModel({
required int id,
required String title,
String? description,
required bool completed,
required String userId,
@JsonKey(includeFromJson: false, includeToJson: false) Map<String, dynamic>? user,
DateTime? createdAt,
DateTime? updatedAt,
}) = _TodoModel;
const TodoModel._();
factory TodoModel.fromJson(Map<String, dynamic> json) =>
_$TodoModelFromJson(json);
/// Convert to domain entity
Todo toEntity() => Todo(
id: id,
title: title,
description: description,
completed: completed,
userId: userId,
createdAt: createdAt,
updatedAt: updatedAt,
);
/// Create from domain entity
factory TodoModel.fromEntity(Todo todo) => TodoModel(
id: todo.id,
title: todo.title,
description: todo.description,
completed: todo.completed,
userId: todo.userId,
createdAt: todo.createdAt,
updatedAt: todo.updatedAt,
);
}

View File

@@ -1,325 +0,0 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'todo_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
TodoModel _$TodoModelFromJson(Map<String, dynamic> json) {
return _TodoModel.fromJson(json);
}
/// @nodoc
mixin _$TodoModel {
int get id => throw _privateConstructorUsedError;
String get title => throw _privateConstructorUsedError;
String? get description => throw _privateConstructorUsedError;
bool get completed => throw _privateConstructorUsedError;
String get userId => throw _privateConstructorUsedError;
@JsonKey(includeFromJson: false, includeToJson: false)
Map<String, dynamic>? get user => throw _privateConstructorUsedError;
DateTime? get createdAt => throw _privateConstructorUsedError;
DateTime? get updatedAt => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$TodoModelCopyWith<TodoModel> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $TodoModelCopyWith<$Res> {
factory $TodoModelCopyWith(TodoModel value, $Res Function(TodoModel) then) =
_$TodoModelCopyWithImpl<$Res, TodoModel>;
@useResult
$Res call(
{int id,
String title,
String? description,
bool completed,
String userId,
@JsonKey(includeFromJson: false, includeToJson: false)
Map<String, dynamic>? user,
DateTime? createdAt,
DateTime? updatedAt});
}
/// @nodoc
class _$TodoModelCopyWithImpl<$Res, $Val extends TodoModel>
implements $TodoModelCopyWith<$Res> {
_$TodoModelCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = null,
Object? title = null,
Object? description = freezed,
Object? completed = null,
Object? userId = null,
Object? user = freezed,
Object? createdAt = freezed,
Object? updatedAt = freezed,
}) {
return _then(_value.copyWith(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as int,
title: null == title
? _value.title
: title // ignore: cast_nullable_to_non_nullable
as String,
description: freezed == description
? _value.description
: description // ignore: cast_nullable_to_non_nullable
as String?,
completed: null == completed
? _value.completed
: completed // ignore: cast_nullable_to_non_nullable
as bool,
userId: null == userId
? _value.userId
: userId // ignore: cast_nullable_to_non_nullable
as String,
user: freezed == user
? _value.user
: user // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
createdAt: freezed == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime?,
updatedAt: freezed == updatedAt
? _value.updatedAt
: updatedAt // ignore: cast_nullable_to_non_nullable
as DateTime?,
) as $Val);
}
}
/// @nodoc
abstract class _$$TodoModelImplCopyWith<$Res>
implements $TodoModelCopyWith<$Res> {
factory _$$TodoModelImplCopyWith(
_$TodoModelImpl value, $Res Function(_$TodoModelImpl) then) =
__$$TodoModelImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{int id,
String title,
String? description,
bool completed,
String userId,
@JsonKey(includeFromJson: false, includeToJson: false)
Map<String, dynamic>? user,
DateTime? createdAt,
DateTime? updatedAt});
}
/// @nodoc
class __$$TodoModelImplCopyWithImpl<$Res>
extends _$TodoModelCopyWithImpl<$Res, _$TodoModelImpl>
implements _$$TodoModelImplCopyWith<$Res> {
__$$TodoModelImplCopyWithImpl(
_$TodoModelImpl _value, $Res Function(_$TodoModelImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = null,
Object? title = null,
Object? description = freezed,
Object? completed = null,
Object? userId = null,
Object? user = freezed,
Object? createdAt = freezed,
Object? updatedAt = freezed,
}) {
return _then(_$TodoModelImpl(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as int,
title: null == title
? _value.title
: title // ignore: cast_nullable_to_non_nullable
as String,
description: freezed == description
? _value.description
: description // ignore: cast_nullable_to_non_nullable
as String?,
completed: null == completed
? _value.completed
: completed // ignore: cast_nullable_to_non_nullable
as bool,
userId: null == userId
? _value.userId
: userId // ignore: cast_nullable_to_non_nullable
as String,
user: freezed == user
? _value._user
: user // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,
createdAt: freezed == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime?,
updatedAt: freezed == updatedAt
? _value.updatedAt
: updatedAt // ignore: cast_nullable_to_non_nullable
as DateTime?,
));
}
}
/// @nodoc
@JsonSerializable()
class _$TodoModelImpl extends _TodoModel {
const _$TodoModelImpl(
{required this.id,
required this.title,
this.description,
required this.completed,
required this.userId,
@JsonKey(includeFromJson: false, includeToJson: false)
final Map<String, dynamic>? user,
this.createdAt,
this.updatedAt})
: _user = user,
super._();
factory _$TodoModelImpl.fromJson(Map<String, dynamic> json) =>
_$$TodoModelImplFromJson(json);
@override
final int id;
@override
final String title;
@override
final String? description;
@override
final bool completed;
@override
final String userId;
final Map<String, dynamic>? _user;
@override
@JsonKey(includeFromJson: false, includeToJson: false)
Map<String, dynamic>? get user {
final value = _user;
if (value == null) return null;
if (_user is EqualUnmodifiableMapView) return _user;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}
@override
final DateTime? createdAt;
@override
final DateTime? updatedAt;
@override
String toString() {
return 'TodoModel(id: $id, title: $title, description: $description, completed: $completed, userId: $userId, user: $user, createdAt: $createdAt, updatedAt: $updatedAt)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$TodoModelImpl &&
(identical(other.id, id) || other.id == id) &&
(identical(other.title, title) || other.title == title) &&
(identical(other.description, description) ||
other.description == description) &&
(identical(other.completed, completed) ||
other.completed == completed) &&
(identical(other.userId, userId) || other.userId == userId) &&
const DeepCollectionEquality().equals(other._user, _user) &&
(identical(other.createdAt, createdAt) ||
other.createdAt == createdAt) &&
(identical(other.updatedAt, updatedAt) ||
other.updatedAt == updatedAt));
}
@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(
runtimeType,
id,
title,
description,
completed,
userId,
const DeepCollectionEquality().hash(_user),
createdAt,
updatedAt);
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$TodoModelImplCopyWith<_$TodoModelImpl> get copyWith =>
__$$TodoModelImplCopyWithImpl<_$TodoModelImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$TodoModelImplToJson(
this,
);
}
}
abstract class _TodoModel extends TodoModel {
const factory _TodoModel(
{required final int id,
required final String title,
final String? description,
required final bool completed,
required final String userId,
@JsonKey(includeFromJson: false, includeToJson: false)
final Map<String, dynamic>? user,
final DateTime? createdAt,
final DateTime? updatedAt}) = _$TodoModelImpl;
const _TodoModel._() : super._();
factory _TodoModel.fromJson(Map<String, dynamic> json) =
_$TodoModelImpl.fromJson;
@override
int get id;
@override
String get title;
@override
String? get description;
@override
bool get completed;
@override
String get userId;
@override
@JsonKey(includeFromJson: false, includeToJson: false)
Map<String, dynamic>? get user;
@override
DateTime? get createdAt;
@override
DateTime? get updatedAt;
@override
@JsonKey(ignore: true)
_$$TodoModelImplCopyWith<_$TodoModelImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -1,33 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'todo_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$TodoModelImpl _$$TodoModelImplFromJson(Map<String, dynamic> json) =>
_$TodoModelImpl(
id: (json['id'] as num).toInt(),
title: json['title'] as String,
description: json['description'] as String?,
completed: json['completed'] as bool,
userId: json['userId'] as String,
createdAt: json['createdAt'] == null
? null
: DateTime.parse(json['createdAt'] as String),
updatedAt: json['updatedAt'] == null
? null
: DateTime.parse(json['updatedAt'] as String),
);
Map<String, dynamic> _$$TodoModelImplToJson(_$TodoModelImpl instance) =>
<String, dynamic>{
'id': instance.id,
'title': instance.title,
'description': instance.description,
'completed': instance.completed,
'userId': instance.userId,
'createdAt': instance.createdAt?.toIso8601String(),
'updatedAt': instance.updatedAt?.toIso8601String(),
};

View File

@@ -1,49 +0,0 @@
import 'package:fpdart/fpdart.dart';
import '../../../../core/errors/exceptions.dart';
import '../../../../core/errors/failures.dart';
import '../../../../core/network/network_info.dart';
import '../../domain/entities/todo.dart';
import '../../domain/repositories/todo_repository.dart';
import '../datasources/todo_remote_datasource.dart';
class TodoRepositoryImpl implements TodoRepository {
final TodoRemoteDataSource remoteDataSource;
final NetworkInfo networkInfo;
TodoRepositoryImpl({
required this.remoteDataSource,
required this.networkInfo,
});
@override
Future<Either<Failure, List<Todo>>> getTodos() async {
if (!await networkInfo.isConnected) {
return const Left(NetworkFailure('No internet connection'));
}
try {
final todos = await remoteDataSource.getTodos();
return Right(todos.map((model) => model.toEntity()).toList());
} on ServerException catch (e) {
return Left(ServerFailure(e.message));
} catch (e) {
return Left(ServerFailure(e.toString()));
}
}
@override
Future<Either<Failure, void>> refreshTodos() async {
if (!await networkInfo.isConnected) {
return const Left(NetworkFailure('No internet connection'));
}
try {
await remoteDataSource.getTodos();
return const Right(null);
} on ServerException catch (e) {
return Left(ServerFailure(e.message));
} catch (e) {
return Left(ServerFailure(e.toString()));
}
}
}

View File

@@ -1,44 +0,0 @@
import 'package:equatable/equatable.dart';
class Todo extends Equatable {
final int id;
final String title;
final String? description;
final bool completed;
final String userId;
final DateTime? createdAt;
final DateTime? updatedAt;
const Todo({
required this.id,
required this.title,
this.description,
required this.completed,
required this.userId,
this.createdAt,
this.updatedAt,
});
Todo copyWith({
int? id,
String? title,
String? description,
bool? completed,
String? userId,
DateTime? createdAt,
DateTime? updatedAt,
}) {
return Todo(
id: id ?? this.id,
title: title ?? this.title,
description: description ?? this.description,
completed: completed ?? this.completed,
userId: userId ?? this.userId,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
);
}
@override
List<Object?> get props => [id, title, description, completed, userId, createdAt, updatedAt];
}

View File

@@ -1,8 +0,0 @@
import 'package:fpdart/fpdart.dart';
import '../../../../core/errors/failures.dart';
import '../entities/todo.dart';
abstract class TodoRepository {
Future<Either<Failure, List<Todo>>> getTodos();
Future<Either<Failure, void>> refreshTodos();
}

View File

@@ -1,112 +0,0 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../../../../core/providers/app_providers.dart';
import '../../../../core/providers/network_providers.dart';
import '../../data/datasources/todo_remote_datasource.dart';
import '../../data/repositories/todo_repository_impl.dart';
import '../../domain/entities/todo.dart';
import '../../domain/repositories/todo_repository.dart';
part 'todo_providers.g.dart';
/// Todo Remote DataSource Provider
@riverpod
TodoRemoteDataSource todoRemoteDataSource(TodoRemoteDataSourceRef ref) {
final dioClient = ref.watch(dioClientProvider);
return TodoRemoteDataSourceImpl(dioClient: dioClient);
}
/// Todo Repository Provider
@riverpod
TodoRepository todoRepository(TodoRepositoryRef ref) {
final remoteDataSource = ref.watch(todoRemoteDataSourceProvider);
final networkInfo = ref.watch(networkInfoProvider);
return TodoRepositoryImpl(
remoteDataSource: remoteDataSource,
networkInfo: networkInfo,
);
}
/// Todos State Provider - Fetches and manages todos list
@riverpod
class Todos extends _$Todos {
@override
Future<List<Todo>> build() async {
// Auto-fetch todos when provider is first accessed
return _fetchTodos();
}
Future<List<Todo>> _fetchTodos() async {
final repository = ref.read(todoRepositoryProvider);
final result = await repository.getTodos();
return result.fold(
(failure) => throw Exception(failure.message),
(todos) => todos,
);
}
/// Refresh todos from API
Future<void> refresh() async {
state = const AsyncValue.loading();
state = await AsyncValue.guard(() => _fetchTodos());
}
/// Toggle todo completion status (local only for now)
void toggleTodo(int id) {
state.whenData((todos) {
final updatedTodos = todos.map((todo) {
if (todo.id == id) {
return todo.copyWith(completed: !todo.completed);
}
return todo;
}).toList();
state = AsyncValue.data(updatedTodos);
});
}
}
/// Filtered Todos Provider - Filter todos by search query
@riverpod
List<Todo> filteredTodos(FilteredTodosRef ref, String searchQuery) {
final todosAsync = ref.watch(todosProvider);
return todosAsync.when(
data: (todos) {
if (searchQuery.isEmpty) {
return todos;
}
return todos.where((todo) {
return todo.title.toLowerCase().contains(searchQuery.toLowerCase()) ||
(todo.description?.toLowerCase().contains(searchQuery.toLowerCase()) ?? false);
}).toList();
},
loading: () => [],
error: (_, __) => [],
);
}
/// Completed Todos Count Provider
@riverpod
int completedTodosCount(CompletedTodosCountRef ref) {
final todosAsync = ref.watch(todosProvider);
return todosAsync.when(
data: (todos) => todos.where((todo) => todo.completed).length,
loading: () => 0,
error: (_, __) => 0,
);
}
/// Pending Todos Count Provider
@riverpod
int pendingTodosCount(PendingTodosCountRef ref) {
final todosAsync = ref.watch(todosProvider);
return todosAsync.when(
data: (todos) => todos.where((todo) => !todo.completed).length,
loading: () => 0,
error: (_, __) => 0,
);
}

View File

@@ -1,259 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'todo_providers.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
String _$todoRemoteDataSourceHash() =>
r'10f103aa6cd7de9c9829c3554f317065c7115575';
/// Todo Remote DataSource Provider
///
/// Copied from [todoRemoteDataSource].
@ProviderFor(todoRemoteDataSource)
final todoRemoteDataSourceProvider =
AutoDisposeProvider<TodoRemoteDataSource>.internal(
todoRemoteDataSource,
name: r'todoRemoteDataSourceProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null
: _$todoRemoteDataSourceHash,
dependencies: null,
allTransitiveDependencies: null,
);
typedef TodoRemoteDataSourceRef = AutoDisposeProviderRef<TodoRemoteDataSource>;
String _$todoRepositoryHash() => r'6830b5ede91b11ac04d0a9430cb84a0f2a8d0905';
/// Todo Repository Provider
///
/// Copied from [todoRepository].
@ProviderFor(todoRepository)
final todoRepositoryProvider = AutoDisposeProvider<TodoRepository>.internal(
todoRepository,
name: r'todoRepositoryProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null
: _$todoRepositoryHash,
dependencies: null,
allTransitiveDependencies: null,
);
typedef TodoRepositoryRef = AutoDisposeProviderRef<TodoRepository>;
String _$filteredTodosHash() => r'b814fe45ea117a5f71e9a223c39c2cfb5fcff61a';
/// Copied from Dart SDK
class _SystemHash {
_SystemHash._();
static int combine(int hash, int value) {
// ignore: parameter_assignments
hash = 0x1fffffff & (hash + value);
// ignore: parameter_assignments
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
return hash ^ (hash >> 6);
}
static int finish(int hash) {
// ignore: parameter_assignments
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
// ignore: parameter_assignments
hash = hash ^ (hash >> 11);
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
}
}
/// Filtered Todos Provider - Filter todos by search query
///
/// Copied from [filteredTodos].
@ProviderFor(filteredTodos)
const filteredTodosProvider = FilteredTodosFamily();
/// Filtered Todos Provider - Filter todos by search query
///
/// Copied from [filteredTodos].
class FilteredTodosFamily extends Family<List<Todo>> {
/// Filtered Todos Provider - Filter todos by search query
///
/// Copied from [filteredTodos].
const FilteredTodosFamily();
/// Filtered Todos Provider - Filter todos by search query
///
/// Copied from [filteredTodos].
FilteredTodosProvider call(
String searchQuery,
) {
return FilteredTodosProvider(
searchQuery,
);
}
@override
FilteredTodosProvider getProviderOverride(
covariant FilteredTodosProvider provider,
) {
return call(
provider.searchQuery,
);
}
static const Iterable<ProviderOrFamily>? _dependencies = null;
@override
Iterable<ProviderOrFamily>? get dependencies => _dependencies;
static const Iterable<ProviderOrFamily>? _allTransitiveDependencies = null;
@override
Iterable<ProviderOrFamily>? get allTransitiveDependencies =>
_allTransitiveDependencies;
@override
String? get name => r'filteredTodosProvider';
}
/// Filtered Todos Provider - Filter todos by search query
///
/// Copied from [filteredTodos].
class FilteredTodosProvider extends AutoDisposeProvider<List<Todo>> {
/// Filtered Todos Provider - Filter todos by search query
///
/// Copied from [filteredTodos].
FilteredTodosProvider(
String searchQuery,
) : this._internal(
(ref) => filteredTodos(
ref as FilteredTodosRef,
searchQuery,
),
from: filteredTodosProvider,
name: r'filteredTodosProvider',
debugGetCreateSourceHash:
const bool.fromEnvironment('dart.vm.product')
? null
: _$filteredTodosHash,
dependencies: FilteredTodosFamily._dependencies,
allTransitiveDependencies:
FilteredTodosFamily._allTransitiveDependencies,
searchQuery: searchQuery,
);
FilteredTodosProvider._internal(
super._createNotifier, {
required super.name,
required super.dependencies,
required super.allTransitiveDependencies,
required super.debugGetCreateSourceHash,
required super.from,
required this.searchQuery,
}) : super.internal();
final String searchQuery;
@override
Override overrideWith(
List<Todo> Function(FilteredTodosRef provider) create,
) {
return ProviderOverride(
origin: this,
override: FilteredTodosProvider._internal(
(ref) => create(ref as FilteredTodosRef),
from: from,
name: null,
dependencies: null,
allTransitiveDependencies: null,
debugGetCreateSourceHash: null,
searchQuery: searchQuery,
),
);
}
@override
AutoDisposeProviderElement<List<Todo>> createElement() {
return _FilteredTodosProviderElement(this);
}
@override
bool operator ==(Object other) {
return other is FilteredTodosProvider && other.searchQuery == searchQuery;
}
@override
int get hashCode {
var hash = _SystemHash.combine(0, runtimeType.hashCode);
hash = _SystemHash.combine(hash, searchQuery.hashCode);
return _SystemHash.finish(hash);
}
}
mixin FilteredTodosRef on AutoDisposeProviderRef<List<Todo>> {
/// The parameter `searchQuery` of this provider.
String get searchQuery;
}
class _FilteredTodosProviderElement
extends AutoDisposeProviderElement<List<Todo>> with FilteredTodosRef {
_FilteredTodosProviderElement(super.provider);
@override
String get searchQuery => (origin as FilteredTodosProvider).searchQuery;
}
String _$completedTodosCountHash() =>
r'9905f3fbd8c17b4cd4edde44d34b36e7b4d1f582';
/// Completed Todos Count Provider
///
/// Copied from [completedTodosCount].
@ProviderFor(completedTodosCount)
final completedTodosCountProvider = AutoDisposeProvider<int>.internal(
completedTodosCount,
name: r'completedTodosCountProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null
: _$completedTodosCountHash,
dependencies: null,
allTransitiveDependencies: null,
);
typedef CompletedTodosCountRef = AutoDisposeProviderRef<int>;
String _$pendingTodosCountHash() => r'f302d2335102b191a27f5ad628d01f9d1cffea05';
/// Pending Todos Count Provider
///
/// Copied from [pendingTodosCount].
@ProviderFor(pendingTodosCount)
final pendingTodosCountProvider = AutoDisposeProvider<int>.internal(
pendingTodosCount,
name: r'pendingTodosCountProvider',
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
? null
: _$pendingTodosCountHash,
dependencies: null,
allTransitiveDependencies: null,
);
typedef PendingTodosCountRef = AutoDisposeProviderRef<int>;
String _$todosHash() => r'2ce152307a44fa5d6173831856732cfe2d082c36';
/// Todos State Provider - Fetches and manages todos list
///
/// Copied from [Todos].
@ProviderFor(Todos)
final todosProvider =
AutoDisposeAsyncNotifierProvider<Todos, List<Todo>>.internal(
Todos.new,
name: r'todosProvider',
debugGetCreateSourceHash:
const bool.fromEnvironment('dart.vm.product') ? null : _$todosHash,
dependencies: null,
allTransitiveDependencies: null,
);
typedef _$Todos = AutoDisposeAsyncNotifier<List<Todo>>;
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member

View File

@@ -1,34 +1,110 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../providers/todo_providers.dart';
class TodoScreen extends ConsumerStatefulWidget { class HomeScreen extends StatefulWidget {
const TodoScreen({super.key}); const HomeScreen({super.key});
@override @override
ConsumerState<TodoScreen> createState() => _TodoScreenState(); State<HomeScreen> createState() => _HomeScreenState();
} }
class _TodoScreenState extends ConsumerState<TodoScreen> { class _HomeScreenState extends State<HomeScreen> {
bool _isLoading = false;
List<Map<String, dynamic>> _todos = [];
String _searchQuery = ''; String _searchQuery = '';
final TextEditingController _searchController = TextEditingController(); final TextEditingController _searchController = TextEditingController();
@override
void initState() {
super.initState();
_loadTodos();
}
@override @override
void dispose() { void dispose() {
_searchController.dispose(); _searchController.dispose();
super.dispose(); super.dispose();
} }
// Mock todos data - will be replaced with API call
Future<void> _loadTodos() async {
setState(() {
_isLoading = true;
});
// Simulate API call delay
await Future.delayed(const Duration(seconds: 1));
// Mock data simulating JSONPlaceholder response
final mockTodos = [
{
'id': 1,
'title': 'Complete project documentation',
'completed': false,
'userId': 1,
},
{
'id': 2,
'title': 'Review code changes',
'completed': true,
'userId': 1,
},
{
'id': 3,
'title': 'Update Flutter dependencies',
'completed': false,
'userId': 1,
},
{
'id': 4,
'title': 'Write unit tests',
'completed': false,
'userId': 2,
},
{
'id': 5,
'title': 'Fix navigation bug',
'completed': true,
'userId': 2,
},
];
if (mounted) {
setState(() {
_todos = mockTodos;
_isLoading = false;
});
}
}
List<Map<String, dynamic>> get _filteredTodos {
if (_searchQuery.isEmpty) {
return _todos;
}
return _todos.where((todo) {
return todo['title']
.toString()
.toLowerCase()
.contains(_searchQuery.toLowerCase());
}).toList();
}
void _toggleTodoStatus(int id) {
setState(() {
final todoIndex = _todos.indexWhere((todo) => todo['id'] == id);
if (todoIndex != -1) {
_todos[todoIndex]['completed'] = !_todos[todoIndex]['completed'];
}
});
}
Future<void> _refreshTodos() async { Future<void> _refreshTodos() async {
await ref.read(todosProvider.notifier).refresh(); await _loadTodos();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final theme = Theme.of(context); final theme = Theme.of(context);
final colorScheme = theme.colorScheme; final colorScheme = theme.colorScheme;
final todosAsync = ref.watch(todosProvider);
final filteredTodos = ref.watch(filteredTodosProvider(_searchQuery));
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@@ -89,61 +165,25 @@ class _TodoScreenState extends ConsumerState<TodoScreen> {
// Todos List // Todos List
Expanded( Expanded(
child: todosAsync.when( child: _isLoading
data: (todos) { ? const Center(
if (todos.isEmpty) { child: CircularProgressIndicator(),
return _buildEmptyState(); )
} : _todos.isEmpty
if (filteredTodos.isEmpty) { ? _buildEmptyState()
return _buildNoResultsState(); : RefreshIndicator(
} onRefresh: _refreshTodos,
return RefreshIndicator( child: _filteredTodos.isEmpty
onRefresh: _refreshTodos, ? _buildNoResultsState()
child: ListView.builder( : ListView.builder(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
itemCount: filteredTodos.length, itemCount: _filteredTodos.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final todo = filteredTodos[index]; final todo = _filteredTodos[index];
return _buildTodoCard(todo); return _buildTodoCard(todo);
}, },
), ),
);
},
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stack) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.error_outline,
size: 64,
color: colorScheme.error,
),
const SizedBox(height: 16),
Text(
'Error loading todos',
style: theme.textTheme.headlineSmall?.copyWith(
color: colorScheme.error,
), ),
),
const SizedBox(height: 8),
Text(
error.toString(),
style: theme.textTheme.bodyMedium?.copyWith(
color: colorScheme.onSurfaceVariant,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
ElevatedButton.icon(
onPressed: _refreshTodos,
icon: const Icon(Icons.refresh),
label: const Text('Retry'),
),
],
),
),
),
), ),
], ],
), ),
@@ -162,10 +202,10 @@ class _TodoScreenState extends ConsumerState<TodoScreen> {
); );
} }
Widget _buildTodoCard(todo) { Widget _buildTodoCard(Map<String, dynamic> todo) {
final theme = Theme.of(context); final theme = Theme.of(context);
final colorScheme = theme.colorScheme; final colorScheme = theme.colorScheme;
final isCompleted = todo.completed; final isCompleted = todo['completed'] as bool;
return Card( return Card(
margin: const EdgeInsets.only(bottom: 8.0), margin: const EdgeInsets.only(bottom: 8.0),
@@ -180,13 +220,13 @@ class _TodoScreenState extends ConsumerState<TodoScreen> {
), ),
leading: Checkbox( leading: Checkbox(
value: isCompleted, value: isCompleted,
onChanged: (_) => ref.read(todosProvider.notifier).toggleTodo(todo.id), onChanged: (_) => _toggleTodoStatus(todo['id']),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4), borderRadius: BorderRadius.circular(4),
), ),
), ),
title: Text( title: Text(
todo.title, todo['title'],
style: theme.textTheme.bodyLarge?.copyWith( style: theme.textTheme.bodyLarge?.copyWith(
decoration: isCompleted ? TextDecoration.lineThrough : null, decoration: isCompleted ? TextDecoration.lineThrough : null,
color: isCompleted color: isCompleted
@@ -194,27 +234,11 @@ class _TodoScreenState extends ConsumerState<TodoScreen> {
: colorScheme.onSurface, : colorScheme.onSurface,
), ),
), ),
subtitle: Column( subtitle: Text(
crossAxisAlignment: CrossAxisAlignment.start, 'ID: ${todo['id']} • User: ${todo['userId']}',
children: [ style: theme.textTheme.bodySmall?.copyWith(
if (todo.description != null && todo.description!.isNotEmpty) color: colorScheme.onSurfaceVariant,
Text( ),
todo.description!,
style: theme.textTheme.bodySmall?.copyWith(
color: colorScheme.onSurfaceVariant,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Text(
'ID: ${todo.id}',
style: theme.textTheme.bodySmall?.copyWith(
color: colorScheme.onSurfaceVariant.withOpacity(0.7),
fontSize: 11,
),
),
],
), ),
trailing: PopupMenuButton<String>( trailing: PopupMenuButton<String>(
onSelected: (value) { onSelected: (value) {

View File

@@ -41,6 +41,62 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.13.0" version: "2.13.0"
audioplayers:
dependency: "direct main"
description:
name: audioplayers
sha256: "5441fa0ceb8807a5ad701199806510e56afde2b4913d9d17c2f19f2902cf0ae4"
url: "https://pub.dev"
source: hosted
version: "6.5.1"
audioplayers_android:
dependency: transitive
description:
name: audioplayers_android
sha256: "60a6728277228413a85755bd3ffd6fab98f6555608923813ce383b190a360605"
url: "https://pub.dev"
source: hosted
version: "5.2.1"
audioplayers_darwin:
dependency: transitive
description:
name: audioplayers_darwin
sha256: "0811d6924904ca13f9ef90d19081e4a87f7297ddc19fc3d31f60af1aaafee333"
url: "https://pub.dev"
source: hosted
version: "6.3.0"
audioplayers_linux:
dependency: transitive
description:
name: audioplayers_linux
sha256: f75bce1ce864170ef5e6a2c6a61cd3339e1a17ce11e99a25bae4474ea491d001
url: "https://pub.dev"
source: hosted
version: "4.2.1"
audioplayers_platform_interface:
dependency: transitive
description:
name: audioplayers_platform_interface
sha256: "0e2f6a919ab56d0fec272e801abc07b26ae7f31980f912f24af4748763e5a656"
url: "https://pub.dev"
source: hosted
version: "7.1.1"
audioplayers_web:
dependency: transitive
description:
name: audioplayers_web
sha256: "1c0f17cec68455556775f1e50ca85c40c05c714a99c5eb1d2d57cc17ba5522d7"
url: "https://pub.dev"
source: hosted
version: "5.1.1"
audioplayers_windows:
dependency: transitive
description:
name: audioplayers_windows
sha256: "4048797865105b26d47628e6abb49231ea5de84884160229251f37dfcbe52fd7"
url: "https://pub.dev"
source: hosted
version: "4.2.1"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
@@ -379,6 +435,14 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
flutter_tts:
dependency: "direct main"
description:
name: flutter_tts
sha256: bdf2fc4483e74450dc9fc6fe6a9b6a5663e108d4d0dad3324a22c8e26bf48af4
url: "https://pub.dev"
source: hosted
version: "4.2.3"
flutter_web_plugins: flutter_web_plugins:
dependency: transitive dependency: transitive
description: flutter description: flutter
@@ -728,6 +792,70 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.5.0" version: "1.5.0"
record:
dependency: "direct main"
description:
name: record
sha256: "9dbc6ff3e784612f90a9b001373c45ff76b7a08abd2bd9fdf72c242320c8911c"
url: "https://pub.dev"
source: hosted
version: "6.1.1"
record_android:
dependency: transitive
description:
name: record_android
sha256: "854627cd78d8d66190377f98477eee06ca96ab7c9f2e662700daf33dbf7e6673"
url: "https://pub.dev"
source: hosted
version: "1.4.2"
record_ios:
dependency: transitive
description:
name: record_ios
sha256: "13e241ed9cbc220534a40ae6b66222e21288db364d96dd66fb762ebd3cb77c71"
url: "https://pub.dev"
source: hosted
version: "1.1.2"
record_linux:
dependency: transitive
description:
name: record_linux
sha256: "235b1f1fb84e810f8149cc0c2c731d7d697f8d1c333b32cb820c449bf7bb72d8"
url: "https://pub.dev"
source: hosted
version: "1.2.1"
record_macos:
dependency: transitive
description:
name: record_macos
sha256: "2849068bb59072f300ad63ed146e543d66afaef8263edba4de4834fc7c8d4d35"
url: "https://pub.dev"
source: hosted
version: "1.1.1"
record_platform_interface:
dependency: transitive
description:
name: record_platform_interface
sha256: b0065fdf1ec28f5a634d676724d388a77e43ce7646fb049949f58c69f3fcb4ed
url: "https://pub.dev"
source: hosted
version: "1.4.0"
record_web:
dependency: transitive
description:
name: record_web
sha256: "4f0adf20c9ccafcc02d71111fd91fba1ca7b17a7453902593e5a9b25b74a5c56"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
record_windows:
dependency: transitive
description:
name: record_windows
sha256: "223258060a1d25c62bae18282c16783f28581ec19401d17e56b5205b9f039d78"
url: "https://pub.dev"
source: hosted
version: "1.0.7"
riverpod: riverpod:
dependency: transitive dependency: transitive
description: description:

View File

@@ -63,6 +63,11 @@ dependencies:
# Image Caching # Image Caching
cached_network_image: ^3.3.1 cached_network_image: ^3.3.1
flutter_tts: ^4.2.3
record: ^6.1.1
audioplayers: ^6.5.1
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter