mirror of
https://github.com/we-promise/sure.git
synced 2026-04-23 14:04:06 +00:00
* Move debug logs button from Home to Settings page, remove refresh/logout from Home AppBar - Remove Debug Logs, Refresh, and Sign Out buttons from DashboardScreen AppBar - Add Debug Logs ListTile entry in SettingsScreen under app info section - Remove unused _handleLogout method from DashboardScreen - Remove unused log_viewer_screen.dart import from DashboardScreen https://claude.ai/code/session_017XQZdaEwUuRS75tJMcHzB9 * Add category picker to Android transaction form Implements category selection when creating transactions in the mobile app. Uses the existing /api/v1/categories endpoint to fetch categories and sends category_id when creating transactions via the API. New files: - Category model, CategoriesService, CategoriesProvider Updated: - Transaction/OfflineTransaction models with categoryId/categoryName - TransactionsService/Provider to pass category_id - DB schema v2 migration for category columns - TransactionFormScreen with category dropdown in "More" section Closes #78 https://claude.ai/code/session_01Dgj8tYrCkoUaLW2WrQ3vMJ * Fix ambiguous Category import in CategoriesProvider Hide Flutter's built-in Category annotation from foundation.dart to resolve name collision with our Category model. https://claude.ai/code/session_01Dgj8tYrCkoUaLW2WrQ3vMJ * Add category filter on Dashboard, clear categories on data reset, fix ambiguous imports - Add CategoryFilter widget (horizontal chip row like CurrencyFilter) - Show category filter on Dashboard below currency filter (2nd row) - Add "Show Category Filter" toggle in Settings > Display section - Clear CategoriesProvider on "Clear Local Data" and "Reset Account" - Fix Category name collision: hide Flutter's Category from material.dart - Add getShowCategoryFilter/setShowCategoryFilter to PreferencesService https://claude.ai/code/session_01Dgj8tYrCkoUaLW2WrQ3vMJ * Fix Category name collision using prefixed imports Use 'import as models' instead of 'hide Category' to avoid undefined_hidden_name warnings with flutter/material.dart. https://claude.ai/code/session_01Dgj8tYrCkoUaLW2WrQ3vMJ * Fix duplicate column error in SQLite migration Check if category_id/category_name columns exist before running ALTER TABLE, preventing crashes when the DB was already at v2 or the migration had partially succeeded. https://claude.ai/code/session_01Dgj8tYrCkoUaLW2WrQ3vMJ * Move CategoryFilter from dashboard to transaction list screen CategoryFilter was filtering accounts on the dashboard but accounts are already grouped by type. Moved it to TransactionsListScreen where it filters transactions by category, which is the correct placement. https://claude.ai/code/session_01Dgj8tYrCkoUaLW2WrQ3vMJ * Add category tag badge next to transaction name Shows an oval-bordered category label after each transaction's name for quick visual identification of transaction types. https://claude.ai/code/session_01Dgj8tYrCkoUaLW2WrQ3vMJ * Address review findings for category feature 1. Category.fromJson now recursively parses parent chain; displayName walks all ancestors (e.g. "Grandparent > Parent > Child") 2. CategoriesProvider.fetchCategories guards against concurrent/duplicate calls by checking _isLoading and _hasFetched early 3. CategoryFilter chips use displayName to distinguish subcategories 4. Transaction badge resolves full displayName from CategoriesProvider with overflow ellipsis for long paths 5. Offline storage preserves local category values when server response omits them (coalesce with ??) https://claude.ai/code/session_01Dgj8tYrCkoUaLW2WrQ3vMJ * Fix missing closing brace in PreferencesService causing theme_provider analyze errors https://claude.ai/code/session_01Dgj8tYrCkoUaLW2WrQ3vMJ * Fix sync category upload, empty-state refresh, badge reactivity, and preferences syntax - Add categoryId to SyncService pending transaction upload payload - Replace non-scrollable Center with ListView for empty filter state so RefreshIndicator works when no transactions match - Use listen:true for CategoriesProvider in badge display so badges rebuild when categories finish loading - Fix missing closing brace in PreferencesService.setShowCategoryFilter https://claude.ai/code/session_01Dgj8tYrCkoUaLW2WrQ3vMJ --------- Signed-off-by: Juan José Mata <juanjo.mata@gmail.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
275 lines
8.0 KiB
Dart
275 lines
8.0 KiB
Dart
import 'dart:async';
|
|
import 'package:app_links/app_links.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'providers/auth_provider.dart';
|
|
import 'providers/accounts_provider.dart';
|
|
import 'providers/categories_provider.dart';
|
|
import 'providers/transactions_provider.dart';
|
|
import 'providers/chat_provider.dart';
|
|
import 'providers/theme_provider.dart';
|
|
import 'screens/backend_config_screen.dart';
|
|
import 'screens/login_screen.dart';
|
|
import 'screens/main_navigation_screen.dart';
|
|
import 'screens/sso_onboarding_screen.dart';
|
|
import 'services/api_config.dart';
|
|
import 'services/connectivity_service.dart';
|
|
import 'services/log_service.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await ApiConfig.initialize();
|
|
|
|
// Add initial log entry
|
|
LogService.instance.info('App', 'Sure app starting...');
|
|
|
|
runApp(const SureApp());
|
|
}
|
|
|
|
class SureApp extends StatelessWidget {
|
|
const SureApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MultiProvider(
|
|
providers: [
|
|
ChangeNotifierProvider(create: (_) => LogService.instance),
|
|
ChangeNotifierProvider(create: (_) => ConnectivityService()),
|
|
ChangeNotifierProvider(create: (_) => AuthProvider()),
|
|
ChangeNotifierProvider(create: (_) => ChatProvider()),
|
|
ChangeNotifierProvider(create: (_) => CategoriesProvider()),
|
|
ChangeNotifierProvider(create: (_) => ThemeProvider()),
|
|
ChangeNotifierProxyProvider<ConnectivityService, AccountsProvider>(
|
|
create: (_) => AccountsProvider(),
|
|
update: (_, connectivityService, accountsProvider) {
|
|
if (accountsProvider == null) {
|
|
final provider = AccountsProvider();
|
|
provider.setConnectivityService(connectivityService);
|
|
return provider;
|
|
} else {
|
|
accountsProvider.setConnectivityService(connectivityService);
|
|
return accountsProvider;
|
|
}
|
|
},
|
|
),
|
|
ChangeNotifierProxyProvider<ConnectivityService, TransactionsProvider>(
|
|
create: (_) => TransactionsProvider(),
|
|
update: (_, connectivityService, transactionsProvider) {
|
|
if (transactionsProvider == null) {
|
|
final provider = TransactionsProvider();
|
|
provider.setConnectivityService(connectivityService);
|
|
return provider;
|
|
} else {
|
|
transactionsProvider.setConnectivityService(connectivityService);
|
|
return transactionsProvider;
|
|
}
|
|
},
|
|
),
|
|
],
|
|
child: Consumer<ThemeProvider>(
|
|
builder: (context, themeProvider, _) => MaterialApp(
|
|
title: 'Sure Finances',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: ThemeData(
|
|
fontFamily: 'Geist',
|
|
fontFamilyFallback: const [
|
|
'Inter',
|
|
'Arial',
|
|
'sans-serif',
|
|
],
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: const Color(0xFF6366F1),
|
|
brightness: Brightness.light,
|
|
),
|
|
useMaterial3: true,
|
|
appBarTheme: const AppBarTheme(
|
|
centerTitle: true,
|
|
elevation: 0,
|
|
),
|
|
cardTheme: CardThemeData(
|
|
elevation: 2,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
inputDecorationTheme: InputDecorationTheme(
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
filled: true,
|
|
),
|
|
elevatedButtonTheme: ElevatedButtonThemeData(
|
|
style: ElevatedButton.styleFrom(
|
|
minimumSize: const Size(double.infinity, 50),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
darkTheme: ThemeData(
|
|
fontFamily: 'Geist',
|
|
fontFamilyFallback: const [
|
|
'Inter',
|
|
'Arial',
|
|
'sans-serif',
|
|
],
|
|
colorScheme: ColorScheme.fromSeed(
|
|
seedColor: const Color(0xFF6366F1),
|
|
brightness: Brightness.dark,
|
|
),
|
|
useMaterial3: true,
|
|
appBarTheme: const AppBarTheme(
|
|
centerTitle: true,
|
|
elevation: 0,
|
|
),
|
|
cardTheme: CardThemeData(
|
|
elevation: 2,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
inputDecorationTheme: InputDecorationTheme(
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
filled: true,
|
|
),
|
|
elevatedButtonTheme: ElevatedButtonThemeData(
|
|
style: ElevatedButton.styleFrom(
|
|
minimumSize: const Size(double.infinity, 50),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
themeMode: themeProvider.themeMode,
|
|
routes: {
|
|
'/config': (context) => const BackendConfigScreen(),
|
|
'/login': (context) => const LoginScreen(),
|
|
'/home': (context) => const MainNavigationScreen(),
|
|
},
|
|
home: const AppWrapper(),
|
|
)),
|
|
);
|
|
}
|
|
}
|
|
|
|
class AppWrapper extends StatefulWidget {
|
|
const AppWrapper({super.key});
|
|
|
|
@override
|
|
State<AppWrapper> createState() => _AppWrapperState();
|
|
}
|
|
|
|
class _AppWrapperState extends State<AppWrapper> {
|
|
bool _isCheckingConfig = true;
|
|
bool _hasBackendUrl = false;
|
|
late final AppLinks _appLinks;
|
|
StreamSubscription<Uri>? _linkSubscription;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_checkBackendConfig();
|
|
_initDeepLinks();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_linkSubscription?.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
void _initDeepLinks() {
|
|
_appLinks = AppLinks();
|
|
|
|
// Handle deep link that launched the app (cold start)
|
|
_appLinks.getInitialLink().then((uri) {
|
|
if (uri != null) _handleDeepLink(uri);
|
|
}).catchError((e, stackTrace) {
|
|
LogService.instance.error('DeepLinks', 'Initial link error: $e\n$stackTrace');
|
|
});
|
|
|
|
// Listen for deep links while app is running
|
|
_linkSubscription = _appLinks.uriLinkStream.listen(
|
|
(uri) => _handleDeepLink(uri),
|
|
onError: (e, stackTrace) {
|
|
LogService.instance.error('DeepLinks', 'Link stream error: $e\n$stackTrace');
|
|
},
|
|
);
|
|
}
|
|
|
|
void _handleDeepLink(Uri uri) {
|
|
if (uri.scheme == 'sureapp' && uri.host == 'oauth') {
|
|
final authProvider = Provider.of<AuthProvider>(context, listen: false);
|
|
authProvider.handleSsoCallback(uri);
|
|
}
|
|
}
|
|
|
|
Future<void> _checkBackendConfig() async {
|
|
final hasUrl = await ApiConfig.initialize();
|
|
if (mounted) {
|
|
setState(() {
|
|
_hasBackendUrl = hasUrl;
|
|
_isCheckingConfig = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
void _onBackendConfigSaved() {
|
|
setState(() {
|
|
_hasBackendUrl = true;
|
|
});
|
|
}
|
|
|
|
void _goToBackendConfig() {
|
|
setState(() {
|
|
_hasBackendUrl = false;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (_isCheckingConfig) {
|
|
return const Scaffold(
|
|
body: Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (!_hasBackendUrl) {
|
|
return BackendConfigScreen(
|
|
onConfigSaved: _onBackendConfigSaved,
|
|
);
|
|
}
|
|
|
|
return Consumer<AuthProvider>(
|
|
builder: (context, authProvider, _) {
|
|
// Only show loading spinner during initial auth check
|
|
if (authProvider.isInitializing) {
|
|
return const Scaffold(
|
|
body: Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (authProvider.isAuthenticated) {
|
|
return const MainNavigationScreen();
|
|
}
|
|
|
|
if (authProvider.ssoOnboardingPending) {
|
|
return const SsoOnboardingScreen();
|
|
}
|
|
|
|
return LoginScreen(
|
|
onGoToSettings: _goToBackendConfig,
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|