feat(App): update Finlytic Flutter app UI and blocs
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../features/favorites/cubit/favorites_cubit.dart';
|
||||
|
||||
/// Reusable animated Favorite Star Toggle Button connected to global FavoritesCubit.
|
||||
class FavoriteStarButton extends StatefulWidget {
|
||||
final String identifier;
|
||||
final String? symbol;
|
||||
final String? name;
|
||||
final double size;
|
||||
final EdgeInsetsGeometry? padding;
|
||||
|
||||
const FavoriteStarButton({
|
||||
super.key,
|
||||
required this.identifier,
|
||||
this.symbol,
|
||||
this.name,
|
||||
this.size = 22,
|
||||
this.padding = const EdgeInsets.all(8),
|
||||
});
|
||||
|
||||
@override
|
||||
State<FavoriteStarButton> createState() => _FavoriteStarButtonState();
|
||||
}
|
||||
|
||||
class _FavoriteStarButtonState extends State<FavoriteStarButton> with SingleTickerProviderStateMixin {
|
||||
late AnimationController _controller;
|
||||
late Animation<double> _scaleAnimation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
);
|
||||
_scaleAnimation = TweenSequence<double>([
|
||||
TweenSequenceItem(tween: Tween(begin: 1.0, end: 1.3), weight: 50),
|
||||
TweenSequenceItem(tween: Tween(begin: 1.3, end: 1.0), weight: 50),
|
||||
]).animate(CurvedAnimation(parent: _controller, curve: Curves.easeInOut));
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onPressed() {
|
||||
_controller.forward(from: 0.0);
|
||||
context.read<FavoritesCubit>().toggleFavorite(
|
||||
widget.identifier,
|
||||
symbol: widget.symbol,
|
||||
name: widget.name,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<FavoritesCubit, FavoritesState>(
|
||||
builder: (context, state) {
|
||||
final isFav = state.isFavorite(widget.identifier) ||
|
||||
(widget.symbol != null && state.isFavorite(widget.symbol!));
|
||||
|
||||
return ScaleTransition(
|
||||
scale: _scaleAnimation,
|
||||
child: IconButton(
|
||||
padding: widget.padding ?? const EdgeInsets.all(8),
|
||||
constraints: const BoxConstraints(),
|
||||
icon: AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
transitionBuilder: (child, anim) => ScaleTransition(scale: anim, child: child),
|
||||
child: Icon(
|
||||
isFav ? Icons.star_rounded : Icons.star_border_rounded,
|
||||
key: ValueKey<bool>(isFav),
|
||||
color: isFav ? Colors.amber : AppTheme.textMuted,
|
||||
size: widget.size,
|
||||
),
|
||||
),
|
||||
onPressed: _onPressed,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../core/network/api_client.dart';
|
||||
import '../../core/network/signalr_service.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../core/theme/theme_picker_dialog.dart';
|
||||
import '../../features/auth/bloc/auth_bloc.dart';
|
||||
import '../../features/auth/models/user_model.dart';
|
||||
import '../../features/search/widgets/asset_search_dialog.dart';
|
||||
|
||||
/// Global System App Bar displaying current tab title, connection status LED, spotlight search, theme switcher, and profile menu.
|
||||
class GlobalAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
final UserModel user;
|
||||
final ApiClient apiClient;
|
||||
final SignalRService signalRService;
|
||||
final String currentTabTitle;
|
||||
|
||||
const GlobalAppBar({
|
||||
super.key,
|
||||
required this.user,
|
||||
required this.apiClient,
|
||||
required this.signalRService,
|
||||
required this.currentTabTitle,
|
||||
});
|
||||
|
||||
@override
|
||||
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final activeTheme = AppTheme.activePreset;
|
||||
|
||||
return AppBar(
|
||||
backgroundColor: activeTheme.cardSurface,
|
||||
elevation: activeTheme.brightness == Brightness.dark ? 0 : 1,
|
||||
title: Row(
|
||||
children: [
|
||||
Icon(Icons.auto_graph_rounded, color: activeTheme.primaryColor, size: 26),
|
||||
const SizedBox(width: 10),
|
||||
Text('Finlytic Enterprise', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: activeTheme.textPrimary)),
|
||||
const SizedBox(width: 12),
|
||||
Text('•', style: TextStyle(color: activeTheme.textMuted, fontSize: 16)),
|
||||
const SizedBox(width: 12),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: activeTheme.glassSurface,
|
||||
borderRadius: BorderRadius.circular(activeTheme.borderRadius * 0.6),
|
||||
border: Border.all(color: activeTheme.glassBorder),
|
||||
),
|
||||
child: Text(
|
||||
currentTabTitle,
|
||||
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 13.5, color: activeTheme.accentColor),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
// Connection Status LED Indicator
|
||||
ListenableBuilder(
|
||||
listenable: signalRService,
|
||||
builder: (context, _) {
|
||||
final isOnline = signalRService.isConnected;
|
||||
final color = isOnline ? activeTheme.primaryColor : activeTheme.accentRed;
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: color.withValues(alpha: 0.4)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
isOnline ? 'Online' : 'Offline',
|
||||
style: TextStyle(color: color, fontSize: 11, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.palette_outlined, color: activeTheme.accentColor),
|
||||
tooltip: 'Design & Theme',
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => const ThemePickerDialog(),
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: activeTheme.primaryColor),
|
||||
tooltip: 'Asset-Suche',
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => AssetSearchDialog(apiClient: apiClient),
|
||||
);
|
||||
},
|
||||
),
|
||||
// User Profile Dropdown Menu
|
||||
PopupMenuButton<String>(
|
||||
offset: const Offset(0, 48),
|
||||
color: activeTheme.cardSurface,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(activeTheme.borderRadius),
|
||||
side: BorderSide(color: activeTheme.glassBorder),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 16,
|
||||
backgroundColor: activeTheme.primaryColor.withValues(alpha: 0.2),
|
||||
child: Text(
|
||||
user.email.isNotEmpty ? user.email[0].toUpperCase() : 'U',
|
||||
style: TextStyle(color: activeTheme.primaryColor, fontWeight: FontWeight.bold, fontSize: 13),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
user.fullName.isNotEmpty ? user.fullName : user.email,
|
||||
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 13, color: activeTheme.textPrimary),
|
||||
),
|
||||
Icon(Icons.arrow_drop_down, color: activeTheme.textMuted),
|
||||
],
|
||||
),
|
||||
),
|
||||
onSelected: (value) {
|
||||
if (value == 'logout') {
|
||||
context.read<AuthBloc>().add(LogoutRequested());
|
||||
} else if (value == 'theme') {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => const ThemePickerDialog(),
|
||||
);
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
enabled: false,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(user.email, style: TextStyle(fontWeight: FontWeight.bold, color: activeTheme.textPrimary)),
|
||||
Text('Rolle: ${user.role}', style: TextStyle(fontSize: 11, color: activeTheme.textMuted)),
|
||||
Divider(color: activeTheme.glassBorder),
|
||||
],
|
||||
),
|
||||
),
|
||||
const PopupMenuItem(
|
||||
value: 'theme',
|
||||
child: Row(children: [Icon(Icons.palette_outlined, size: 18), SizedBox(width: 8), Text('Design & Themes')]),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: 'logout',
|
||||
child: Row(children: [Icon(Icons.logout, color: activeTheme.accentRed, size: 18), const SizedBox(width: 8), Text('Abmelden', style: TextStyle(color: activeTheme.accentRed))]),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../core/network/api_client.dart';
|
||||
import '../../core/network/signalr_service.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
import '../../core/theme/theme_cubit.dart';
|
||||
import '../../features/admin/views/admin_users_screen.dart';
|
||||
import '../../features/auth/models/user_model.dart';
|
||||
import '../../features/calendar/views/corporate_calendar_screen.dart';
|
||||
import '../../features/dashboard/views/dashboard_screen.dart';
|
||||
import '../../features/discovery/cubit/discovery_cubit.dart';
|
||||
import '../../features/favorites/cubit/favorites_cubit.dart';
|
||||
|
||||
import '../../features/favorites/views/favorites_screen.dart';
|
||||
import '../../features/news/views/news_feed_screen.dart';
|
||||
import '../../features/trades/views/trades_feed_screen.dart';
|
||||
import 'global_app_bar.dart';
|
||||
|
||||
/// Main Responsive Shell consuming root FavoritesCubit and ThemeCubit state.
|
||||
class ResponsiveScaffold extends StatefulWidget {
|
||||
final UserModel user;
|
||||
final ApiClient apiClient;
|
||||
final SignalRService signalRService;
|
||||
|
||||
const ResponsiveScaffold({
|
||||
super.key,
|
||||
required this.user,
|
||||
required this.apiClient,
|
||||
required this.signalRService,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ResponsiveScaffold> createState() => _ResponsiveScaffoldState();
|
||||
}
|
||||
|
||||
class _ResponsiveScaffoldState extends State<ResponsiveScaffold> {
|
||||
int _selectedIndex = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Load favorites immediately after auth is confirmed and widget is mounted.
|
||||
// Using addPostFrameCallback ensures the BlocProvider tree is fully built.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
context.read<FavoritesCubit>().loadFavorites();
|
||||
context.read<DiscoveryCubit>().loadDiscovery();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
List<String> get _tabTitles => [
|
||||
'Dashboard',
|
||||
'News Feed',
|
||||
'Favoriten',
|
||||
'Kalender',
|
||||
'Live Trades',
|
||||
if (widget.user.isAdmin) 'Admin Panel',
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bool isDesktop = MediaQuery.of(context).size.width >= 800;
|
||||
final titles = _tabTitles;
|
||||
final activeTitle = _selectedIndex < titles.length ? titles[_selectedIndex] : 'Dashboard';
|
||||
|
||||
final List<Widget> pages = [
|
||||
DashboardScreen(apiClient: widget.apiClient, signalRService: widget.signalRService),
|
||||
NewsFeedScreen(apiClient: widget.apiClient),
|
||||
FavoritesScreen(apiClient: widget.apiClient),
|
||||
CorporateCalendarScreen(apiClient: widget.apiClient),
|
||||
TradesFeedScreen(apiClient: widget.apiClient, signalRService: widget.signalRService),
|
||||
if (widget.user.isAdmin) AdminUsersScreen(apiClient: widget.apiClient, signalRService: widget.signalRService),
|
||||
];
|
||||
|
||||
return BlocBuilder<ThemeCubit, ThemeState>(
|
||||
builder: (context, themeState) {
|
||||
final activeTheme = themeState.preset;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: activeTheme.darkBackground,
|
||||
appBar: GlobalAppBar(
|
||||
user: widget.user,
|
||||
apiClient: widget.apiClient,
|
||||
signalRService: widget.signalRService,
|
||||
currentTabTitle: activeTitle,
|
||||
),
|
||||
body: isDesktop
|
||||
? Row(
|
||||
children: [
|
||||
_DesktopSidebar(
|
||||
selectedIndex: _selectedIndex,
|
||||
isAdmin: widget.user.isAdmin,
|
||||
onDestinationSelected: (idx) => setState(() => _selectedIndex = idx),
|
||||
),
|
||||
VerticalDivider(width: 1, color: activeTheme.glassBorder),
|
||||
Expanded(
|
||||
child: AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: pages[_selectedIndex],
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: pages[_selectedIndex],
|
||||
),
|
||||
bottomNavigationBar: isDesktop
|
||||
? null
|
||||
: BottomNavigationBar(
|
||||
currentIndex: _selectedIndex,
|
||||
onTap: (idx) => setState(() => _selectedIndex = idx),
|
||||
backgroundColor: activeTheme.cardSurface,
|
||||
selectedItemColor: activeTheme.primaryColor,
|
||||
unselectedItemColor: activeTheme.textMuted,
|
||||
type: BottomNavigationBarType.fixed,
|
||||
items: [
|
||||
const BottomNavigationBarItem(icon: Icon(Icons.dashboard_rounded), label: 'Dashboard'),
|
||||
const BottomNavigationBarItem(icon: Icon(Icons.newspaper_rounded), label: 'News'),
|
||||
const BottomNavigationBarItem(icon: Icon(Icons.star_rounded), label: 'Favoriten'),
|
||||
const BottomNavigationBarItem(icon: Icon(Icons.calendar_month_rounded), label: 'Kalender'),
|
||||
const BottomNavigationBarItem(icon: Icon(Icons.candlestick_chart_rounded), label: 'Trades'),
|
||||
if (widget.user.isAdmin)
|
||||
const BottomNavigationBarItem(icon: Icon(Icons.admin_panel_settings_outlined), label: 'Admin'),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DesktopSidebar extends StatelessWidget {
|
||||
final int selectedIndex;
|
||||
final bool isAdmin;
|
||||
final ValueChanged<int> onDestinationSelected;
|
||||
|
||||
const _DesktopSidebar({
|
||||
required this.selectedIndex,
|
||||
required this.isAdmin,
|
||||
required this.onDestinationSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final activeTheme = AppTheme.activePreset;
|
||||
|
||||
return Container(
|
||||
width: 220,
|
||||
color: activeTheme.cardSurface,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
children: [
|
||||
_navTile(activeTheme, 0, Icons.dashboard_rounded, 'Dashboard'),
|
||||
_navTile(activeTheme, 1, Icons.newspaper_rounded, 'News Feed'),
|
||||
_navTile(activeTheme, 2, Icons.star_rounded, 'Favoriten'),
|
||||
_navTile(activeTheme, 3, Icons.calendar_month_rounded, 'Kalender'),
|
||||
_navTile(activeTheme, 4, Icons.candlestick_chart_rounded, 'Live Trades'),
|
||||
if (isAdmin) _navTile(activeTheme, 5, Icons.admin_panel_settings_outlined, 'Admin Panel'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _navTile(ThemePreset activeTheme, int index, IconData icon, String label) {
|
||||
final isSelected = selectedIndex == index;
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 3),
|
||||
child: ListTile(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(activeTheme.borderRadius * 0.7)),
|
||||
selected: isSelected,
|
||||
selectedTileColor: activeTheme.primaryColor.withValues(alpha: 0.15),
|
||||
leading: Icon(icon, color: isSelected ? activeTheme.primaryColor : activeTheme.textSecondary, size: 20),
|
||||
title: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: isSelected ? activeTheme.primaryColor : activeTheme.textSecondary,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
onTap: () => onDestinationSelected(index),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user