feat(App): update Finlytic Flutter app UI and blocs

This commit is contained in:
2026-08-09 21:01:46 +02:00
parent e7427b7464
commit a708d2977c
591 changed files with 1095105 additions and 0 deletions
@@ -0,0 +1,65 @@
import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:finlytic_app/features/calendar/repositories/calendar_repository.dart';
import 'calendar_event.dart';
import 'calendar_state.dart';
export 'calendar_event.dart';
export 'calendar_state.dart';
class CalendarBloc extends Bloc<CalendarEvent, CalendarState> {
final CalendarRepository repository;
CalendarBloc({required this.repository}) : super(CalendarInitial()) {
on<FetchCalendarEvents>(_onFetchEvents);
on<FilterCategoryChanged>(_onFilterCategoryChanged);
on<FilterDateSelected>(_onFilterDateSelected);
on<MonthChanged>(_onMonthChanged);
}
Future<void> _onFetchEvents(FetchCalendarEvents event, Emitter<CalendarState> emit) async {
emit(CalendarLoading());
try {
final events = await repository.fetchEvents();
emit(CalendarLoaded(
allEvents: events,
currentMonth: DateTime.now(),
));
} catch (e) {
emit(const CalendarError("Fehler beim Laden des Kalenders."));
}
}
void _onFilterCategoryChanged(FilterCategoryChanged event, Emitter<CalendarState> emit) {
if (state is CalendarLoaded) {
final current = state as CalendarLoaded;
emit(current.copyWith(selectedCategory: event.category));
}
}
void _onFilterDateSelected(FilterDateSelected event, Emitter<CalendarState> emit) {
if (state is CalendarLoaded) {
final current = state as CalendarLoaded;
if (event.date == null) {
emit(current.copyWith(clearSelectedDate: true));
} else if (current.selectedDate != null &&
current.selectedDate!.year == event.date!.year &&
current.selectedDate!.month == event.date!.month &&
current.selectedDate!.day == event.date!.day) {
emit(current.copyWith(clearSelectedDate: true));
} else {
emit(current.copyWith(selectedDate: event.date));
}
}
}
void _onMonthChanged(MonthChanged event, Emitter<CalendarState> emit) {
if (state is CalendarLoaded) {
final current = state as CalendarLoaded;
emit(current.copyWith(
currentMonth: event.newMonth,
clearSelectedDate: true,
));
}
}
}
@@ -0,0 +1,37 @@
import 'package:equatable/equatable.dart';
abstract class CalendarEvent extends Equatable {
const CalendarEvent();
@override
List<Object?> get props => [];
}
class FetchCalendarEvents extends CalendarEvent {}
class FilterCategoryChanged extends CalendarEvent {
final String category;
const FilterCategoryChanged(this.category);
@override
List<Object?> get props => [category];
}
class FilterDateSelected extends CalendarEvent {
final DateTime? date;
const FilterDateSelected(this.date);
@override
List<Object?> get props => [date];
}
class MonthChanged extends CalendarEvent {
final DateTime newMonth;
const MonthChanged(this.newMonth);
@override
List<Object?> get props => [newMonth];
}
@@ -0,0 +1,70 @@
import 'package:equatable/equatable.dart';
import 'package:finlytic_app/features/calendar/models/corporate_event_model.dart';
abstract class CalendarState extends Equatable {
const CalendarState();
@override
List<Object?> get props => [];
}
class CalendarInitial extends CalendarState {}
class CalendarLoading extends CalendarState {}
class CalendarLoaded extends CalendarState {
final List<CorporateEventModel> allEvents;
final String selectedCategory;
final DateTime currentMonth;
final DateTime? selectedDate;
const CalendarLoaded({
required this.allEvents,
this.selectedCategory = 'Alle',
required this.currentMonth,
this.selectedDate,
});
List<CorporateEventModel> get filteredEvents {
return allEvents.where((e) {
if (selectedCategory != 'Alle' && e.eventType != selectedCategory) {
return false;
}
if (selectedDate != null) {
if (e.eventDate.year != selectedDate!.year ||
e.eventDate.month != selectedDate!.month ||
e.eventDate.day != selectedDate!.day) {
return false;
}
}
return true;
}).toList();
}
CalendarLoaded copyWith({
List<CorporateEventModel>? allEvents,
String? selectedCategory,
DateTime? currentMonth,
DateTime? selectedDate,
bool clearSelectedDate = false,
}) {
return CalendarLoaded(
allEvents: allEvents ?? this.allEvents,
selectedCategory: selectedCategory ?? this.selectedCategory,
currentMonth: currentMonth ?? this.currentMonth,
selectedDate: clearSelectedDate ? null : (selectedDate ?? this.selectedDate),
);
}
@override
List<Object?> get props => [allEvents, selectedCategory, currentMonth, selectedDate];
}
class CalendarError extends CalendarState {
final String message;
const CalendarError(this.message);
@override
List<Object?> get props => [message];
}
@@ -0,0 +1,60 @@
import 'package:equatable/equatable.dart';
class CorporateEventModel extends Equatable {
final String id;
final String symbol;
final String companyName;
final String eventType;
final DateTime eventDate;
final String description;
const CorporateEventModel({
required this.id,
required this.symbol,
required this.companyName,
required this.eventType,
required this.eventDate,
required this.description,
});
factory CorporateEventModel.fromJson(Map<String, dynamic> json) {
DateTime parseDate(dynamic raw) {
if (raw == null) return DateTime(1970);
final str = raw.toString();
try {
if (str.contains('.')) {
final parts = str.split('.');
if (parts.length >= 3) {
return DateTime(int.parse(parts[2]), int.parse(parts[1]), int.parse(parts[0]));
}
}
return DateTime.parse(str);
} catch (_) {
return DateTime(1970);
}
}
return CorporateEventModel(
id: json['id']?.toString() ?? json['Id']?.toString() ?? '',
symbol: json['symbol']?.toString() ?? json['Symbol']?.toString() ?? '',
companyName: json['companyName']?.toString() ?? json['CompanyName']?.toString() ?? '',
eventType: json['eventType']?.toString() ?? json['EventType']?.toString() ?? '',
eventDate: parseDate(json['eventDate'] ?? json['EventDate']),
description: json['description']?.toString() ?? json['Description']?.toString() ?? '',
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'symbol': symbol,
'companyName': companyName,
'eventType': eventType,
'eventDate': eventDate.toIso8601String(),
'description': description,
};
}
@override
List<Object?> get props => [id, symbol, companyName, eventType, eventDate, description];
}
@@ -0,0 +1,22 @@
import 'package:finlytic_app/core/network/api_client.dart';
import 'package:finlytic_app/features/calendar/models/corporate_event_model.dart';
class CalendarRepository {
final ApiClient apiClient;
CalendarRepository({required this.apiClient});
Future<List<CorporateEventModel>> fetchEvents() async {
try {
final res = await apiClient.get('/api/v1/calendar');
if (res.statusCode == 200 && res.data != null) {
final List<dynamic> data = res.data;
return data.map((json) => CorporateEventModel.fromJson(json)).toList();
}
return [];
} catch (e) {
print('Error fetching calendar events: $e');
throw Exception('Kalender-Termine konnten nicht geladen werden');
}
}
}
@@ -0,0 +1,179 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../core/network/api_client.dart';
import '../../../core/theme/app_theme.dart';
import '../bloc/calendar_bloc.dart';
import '../repositories/calendar_repository.dart';
import '../widgets/calendar_event_tile.dart';
import '../widgets/month_calendar_widget.dart';
/// Corporate Calendar Screen featuring a compact interactive monthly calendar grid,
/// event count indicators, category filters, and tile view (Kachelansicht) for events.
class CorporateCalendarScreen extends StatelessWidget {
final ApiClient apiClient;
const CorporateCalendarScreen({super.key, required this.apiClient});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => CalendarBloc(
repository: CalendarRepository(apiClient: apiClient),
)..add(FetchCalendarEvents()),
child: _CorporateCalendarScreenContent(apiClient: apiClient),
);
}
}
class _CorporateCalendarScreenContent extends StatelessWidget {
final ApiClient apiClient;
const _CorporateCalendarScreenContent({required this.apiClient});
static const List<String> categories = ['Alle', 'Earnings', 'ExDividend', 'Payout'];
@override
Widget build(BuildContext context) {
return Scaffold(
body: BlocBuilder<CalendarBloc, CalendarState>(
builder: (context, state) {
if (state is CalendarLoading) {
return Center(
child: CircularProgressIndicator(color: AppTheme.primaryEmerald),
);
}
if (state is CalendarError) {
return Center(
child: Text(state.message, style: TextStyle(color: AppTheme.textMuted)),
);
}
if (state is CalendarLoaded) {
final filtered = state.filteredEvents;
return SingleChildScrollView(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MonthCalendarWidget(
currentMonth: state.currentMonth,
selectedDate: state.selectedDate,
events: state.allEvents.map((e) => e.toJson()).toList(),
onDateSelected: (date) {
context.read<CalendarBloc>().add(FilterDateSelected(date));
},
onMonthChanged: (newMonth) {
context.read<CalendarBloc>().add(MonthChanged(newMonth));
},
),
const SizedBox(height: 18),
Row(
children: [
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: categories.map((cat) {
final isSelected = state.selectedCategory == cat;
String label = 'Alle';
if (cat == 'Earnings') label = 'Quartalsergebnisse';
if (cat == 'ExDividend') label = 'Ex-Dividendentage';
if (cat == 'Payout') label = 'Zahlungstage';
return Padding(
padding: const EdgeInsets.only(right: 8),
child: ChoiceChip(
label: Text(label),
selected: isSelected,
selectedColor: AppTheme.primaryEmerald.withValues(alpha: 0.25),
backgroundColor: AppTheme.glassSurface,
labelStyle: TextStyle(
color: isSelected ? AppTheme.primaryEmerald : AppTheme.textSecondary,
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
fontSize: 12,
),
side: BorderSide(color: isSelected ? AppTheme.primaryEmerald : AppTheme.glassBorder),
onSelected: (_) {
context.read<CalendarBloc>().add(FilterCategoryChanged(cat));
},
),
);
}).toList(),
),
),
),
if (state.selectedDate != null)
TextButton.icon(
onPressed: () {
context.read<CalendarBloc>().add(const FilterDateSelected(null));
},
icon: Icon(Icons.clear, size: 14, color: AppTheme.accentCyan),
label: Text('Alle Tage', style: TextStyle(color: AppTheme.accentCyan, fontSize: 12)),
),
],
),
const SizedBox(height: 14),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
state.selectedDate != null
? 'Termine am ${state.selectedDate!.day.toString().padLeft(2, '0')}.${state.selectedDate!.month.toString().padLeft(2, '0')}.${state.selectedDate!.year} (${filtered.length})'
: 'Anstehende Termine (${filtered.length})',
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold, color: AppTheme.textPrimary),
),
Text('Kachelansicht', style: TextStyle(fontSize: 11, color: AppTheme.textMuted)),
],
),
const SizedBox(height: 12),
filtered.isEmpty
? Container(
width: double.infinity,
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: AppTheme.glassSurface,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: AppTheme.glassBorder),
),
child: Center(
child: Text(
'Keine Unternehmenstermine für diesen Filter/Tag gefunden.',
style: TextStyle(color: AppTheme.textMuted, fontSize: 13),
),
),
)
: LayoutBuilder(
builder: (context, constraints) {
final crossAxisCount = constraints.maxWidth > 750 ? 4 : (constraints.maxWidth > 480 ? 2 : 1);
return GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: filtered.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAxisCount,
childAspectRatio: 3,
crossAxisSpacing: 12,
mainAxisSpacing: 12,
),
itemBuilder: (context, index) {
return CalendarEventTile(
event: filtered[index].toJson(),
apiClient: apiClient,
);
},
);
},
),
],
),
);
}
return const SizedBox.shrink();
},
),
);
}
}
@@ -0,0 +1,62 @@
import 'package:flutter/material.dart';
import '../../../core/theme/app_theme.dart';
import '../../../core/widgets/glass_container.dart';
import '../../../core/widgets/status_badge.dart';
/// Corporate Calendar event item widget.
class CalendarEventItem extends StatelessWidget {
final Map<String, dynamic> event;
const CalendarEventItem({super.key, required this.event});
@override
Widget build(BuildContext context) {
final symbol = event['symbol']?.toString() ?? 'ASSET';
final company = event['companyName']?.toString() ?? symbol;
final type = event['eventType']?.toString() ?? 'Earnings';
final desc = event['description']?.toString() ?? '';
final dateStr = event['eventDate']?.toString() ?? '';
Color badgeColor = AppTheme.primaryEmerald;
if (type == 'ExDividend') badgeColor = AppTheme.accentCyan;
if (type == 'Payout') badgeColor = Colors.amber;
return GlassContainer(
margin: const EdgeInsets.only(bottom: 10),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: badgeColor.withValues(alpha: 0.15),
borderRadius: BorderRadius.circular(10),
),
child: Icon(
type == 'Earnings' ? Icons.bar_chart : (type == 'ExDividend' ? Icons.content_cut : Icons.payments),
color: badgeColor,
),
),
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text('$company ($symbol)', style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 14)),
const Spacer(),
StatusBadge(label: type, color: badgeColor),
],
),
const SizedBox(height: 4),
Text(desc, style: TextStyle(color: AppTheme.textSecondary, fontSize: 12)),
const SizedBox(height: 4),
Text('Datum: $dateStr', style: TextStyle(color: AppTheme.textMuted, fontSize: 11)),
],
),
),
],
),
);
}
}
@@ -0,0 +1,116 @@
import 'package:flutter/material.dart';
import '../../../core/network/api_client.dart';
import '../../../core/theme/app_theme.dart';
import '../../../core/utils/asset_utils.dart';
import '../../../core/widgets/asset_logo_widget.dart';
import '../../../core/widgets/glass_container.dart';
import '../../../core/widgets/status_badge.dart';
import '../../asset_detail/views/asset_detail_screen.dart';
/// Glassmorphic Event Tile widget for Corporate Calendar (Kachelansicht).
class CalendarEventTile extends StatelessWidget {
final Map<String, dynamic> event;
final ApiClient apiClient;
const CalendarEventTile({
super.key,
required this.event,
required this.apiClient,
});
@override
Widget build(BuildContext context) {
final rawSymbol = event['symbol']?.toString() ?? event['Symbol']?.toString() ?? 'ASSET';
final rawCompany = event['companyName']?.toString() ?? event['CompanyName']?.toString() ?? rawSymbol;
final displayName = AssetUtils.getAssetName(rawCompany.isNotEmpty ? rawCompany : rawSymbol);
final type = event['eventType']?.toString() ?? event['EventType']?.toString() ?? 'Earnings';
final desc = event['description']?.toString() ?? event['Description']?.toString() ?? '';
final dateStr = event['eventDate']?.toString() ?? event['EventDate']?.toString() ?? '';
String formattedDate = dateStr;
try {
final dt = DateTime.parse(dateStr);
formattedDate = '${dt.day.toString().padLeft(2, '0')}.${dt.month.toString().padLeft(2, '0')}.${dt.year}';
} catch (_) {}
Color badgeColor = AppTheme.primaryEmerald;
String typeLabel = 'Quartalszahlen';
if (type == 'ExDividend') {
badgeColor = AppTheme.accentCyan;
typeLabel = 'Ex-Dividende';
} else if (type == 'Payout') {
badgeColor = Colors.amber;
typeLabel = 'Zahlungstag';
}
return GlassContainer(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => AssetDetailScreen(
symbol: displayName,
apiClient: apiClient,
),
),
);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Row(
children: [
AssetLogoWidget(symbolOrName: displayName, size: 28),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
displayName,
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 13.5),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Text(
rawSymbol,
style: TextStyle(color: AppTheme.textMuted, fontSize: 10),
),
],
),
),
],
),
),
StatusBadge(label: typeLabel, color: badgeColor),
],
),
const SizedBox(height: 6),
Text(
desc,
style: TextStyle(color: AppTheme.textSecondary, fontSize: 12),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 6),
Row(
children: [
Text('Termin:', style: TextStyle(color: AppTheme.textMuted, fontSize: 10.5)),
const SizedBox(width: 6),
Text(
formattedDate,
style: TextStyle(color: AppTheme.accentCyan, fontWeight: FontWeight.bold, fontSize: 11),
),
],
),
],
),
);
}
}
@@ -0,0 +1,192 @@
import 'package:flutter/material.dart';
import '../../../core/theme/app_theme.dart';
import '../../../core/widgets/glass_container.dart';
/// Compact Interactive Monthly Calendar Grid with event markers and event count dots.
class MonthCalendarWidget extends StatelessWidget {
final DateTime currentMonth;
final DateTime? selectedDate;
final List<dynamic> events;
final Function(DateTime) onDateSelected;
final Function(DateTime) onMonthChanged;
const MonthCalendarWidget({
super.key,
required this.currentMonth,
required this.selectedDate,
required this.events,
required this.onDateSelected,
required this.onMonthChanged,
});
static const List<String> weekDays = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'];
static const List<String> monthNames = [
'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni',
'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'
];
DateTime _parseEventDate(dynamic raw) {
if (raw == null) return DateTime(1970);
final str = raw.toString();
try {
if (str.contains('.')) {
final parts = str.split('.');
if (parts.length >= 3) {
return DateTime(int.parse(parts[2]), int.parse(parts[1]), int.parse(parts[0]));
}
}
return DateTime.parse(str);
} catch (_) {
return DateTime(1970);
}
}
List<dynamic> _getEventsForDate(DateTime date) {
return events.where((e) {
final dt = _parseEventDate(e['eventDate'] ?? e['EventDate']);
return dt.year == date.year && dt.month == date.month && dt.day == date.day;
}).toList();
}
@override
Widget build(BuildContext context) {
final firstDayOfMonth = DateTime(currentMonth.year, currentMonth.month, 1);
final daysInMonth = DateTime(currentMonth.year, currentMonth.month + 1, 0).day;
// ISO weekday: Monday = 1, Sunday = 7
final firstWeekday = firstDayOfMonth.weekday;
final leadingEmptyDays = firstWeekday - 1;
final totalCells = ((leadingEmptyDays + daysInMonth) / 7).ceil() * 7;
return Center(
child: Container(
child: GlassContainer(
padding: const EdgeInsets.all(12),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Month Header Navigation
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: Icon(Icons.chevron_left, color: AppTheme.accentCyan, size: 20),
padding: EdgeInsets.zero,
constraints: const BoxConstraints(),
onPressed: () => onMonthChanged(DateTime(currentMonth.year, currentMonth.month - 1, 1)),
),
Text(
'${monthNames[currentMonth.month - 1]} ${currentMonth.year}',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14, color: AppTheme.textPrimary),
),
IconButton(
icon: Icon(Icons.chevron_right, color: AppTheme.accentCyan, size: 20),
padding: EdgeInsets.zero,
constraints: const BoxConstraints(),
onPressed: () => onMonthChanged(DateTime(currentMonth.year, currentMonth.month + 1, 1)),
),
],
),
const SizedBox(height: 6),
// Weekday Labels
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: weekDays.map((w) => Expanded(
child: Center(
child: Text(
w,
style: TextStyle(color: AppTheme.textMuted, fontSize: 11, fontWeight: FontWeight.bold),
),
),
)).toList(),
),
const SizedBox(height: 4),
// Days Grid
GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: totalCells,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 7,
childAspectRatio: 2,
),
itemBuilder: (context, index) {
final dayNumber = index - leadingEmptyDays + 1;
if (dayNumber < 1 || dayNumber > daysInMonth) {
return const SizedBox();
}
final cellDate = DateTime(currentMonth.year, currentMonth.month, dayNumber);
final isSelected = selectedDate != null &&
selectedDate!.year == cellDate.year &&
selectedDate!.month == cellDate.month &&
selectedDate!.day == cellDate.day;
final isToday = DateTime.now().year == cellDate.year &&
DateTime.now().month == cellDate.month &&
DateTime.now().day == cellDate.day;
final dayEvents = _getEventsForDate(cellDate);
final eventCount = dayEvents.length;
return InkWell(
onTap: () => onDateSelected(cellDate),
borderRadius: BorderRadius.circular(6),
child: Container(
margin: const EdgeInsets.all(1.5),
decoration: BoxDecoration(
color: isSelected
? AppTheme.primaryEmerald.withValues(alpha: 0.3)
: (isToday ? AppTheme.glassSurface : Colors.transparent),
borderRadius: BorderRadius.circular(6),
border: Border.all(
color: isSelected
? AppTheme.primaryEmerald
: (eventCount > 0 ? AppTheme.accentCyan.withValues(alpha: 0.6) : Colors.transparent),
width: isSelected ? 1.5 : 1.0,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'$dayNumber',
style: TextStyle(
fontSize: 11.5,
fontWeight: isSelected || isToday || eventCount > 0 ? FontWeight.bold : FontWeight.normal,
color: isSelected
? AppTheme.primaryEmerald
: (eventCount > 0 ? AppTheme.textPrimary : AppTheme.textSecondary),
),
),
if (eventCount > 0) ...[
const SizedBox(height: 1),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(
eventCount > 4 ? 4 : eventCount,
(i) => Container(
margin: const EdgeInsets.symmetric(horizontal: 1),
width: 4,
height: 4,
decoration: BoxDecoration(
color: AppTheme.accentCyan,
shape: BoxShape.circle,
),
),
),
),
],
],
),
),
);
},
),
],
),
),
),
);
}
}