Merge NDM-App-195: Home Screen — router, providers, TasksScreen scaffold

This commit is contained in:
TrochtaOndrej
2026-03-18 04:37:18 +01:00
9 changed files with 408 additions and 135 deletions
+35
View File
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../features/tasks/screens/tasks_screen.dart';
import 'routes.dart';
/// GoRouter configuration provider.
final routerProvider = Provider<GoRouter>((ref) {
return GoRouter(
initialLocation: Routes.home,
routes: [
GoRoute(
path: Routes.home,
builder: (context, state) => const TasksScreen(),
),
GoRoute(
path: Routes.addTask,
builder: (context, state) => const _AddTaskPlaceholder(),
),
],
);
});
class _AddTaskPlaceholder extends StatelessWidget {
const _AddTaskPlaceholder();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Novy ukol')),
body: const Center(child: Text('Formulář pro nový úkol')),
);
}
}
+5
View File
@@ -0,0 +1,5 @@
/// Route name constants for go_router navigation.
abstract final class Routes {
static const home = '/';
static const addTask = '/add-task';
}
@@ -0,0 +1,27 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../domain/entities/pet_state.dart';
/// Provider for pet companion state.
final petStateProvider =
NotifierProvider<PetStateNotifier, PetState>(PetStateNotifier.new);
class PetStateNotifier extends Notifier<PetState> {
@override
PetState build() => const PetState();
void onTaskCompleted() {
state = state.copyWith(
totalTasksDone: state.totalTasksDone + 1,
mood: 'happy',
);
}
void setEnergy(int energy) {
state = state.copyWith(energyToday: energy);
}
void incrementStreak() {
state = state.copyWith(streakDays: state.streakDays + 1);
}
}
@@ -0,0 +1,73 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../domain/entities/task.dart';
import '../../../domain/entities/task_status.dart';
/// Provider for today's task list.
final todayTasksProvider =
NotifierProvider<TodayTasksNotifier, List<Task>>(TodayTasksNotifier.new);
class TodayTasksNotifier extends Notifier<List<Task>> {
@override
List<Task> build() => _seedTasks();
void addTask(Task task) {
state = [...state, task];
}
void completeTask(String id) {
state = [
for (final task in state)
if (task.id == id)
task.copyWith(status: TaskStatus.done, updatedAt: DateTime.now())
else
task,
];
}
void uncompleteTask(String id) {
state = [
for (final task in state)
if (task.id == id)
task.copyWith(status: TaskStatus.pending, updatedAt: DateTime.now())
else
task,
];
}
/// Seed tasks for demo/development.
static List<Task> _seedTasks() {
final now = DateTime.now();
return [
Task(
id: '1',
title: 'Odpovedet na emaily',
energyLevel: 1,
createdAt: now,
updatedAt: now,
),
Task(
id: '2',
title: 'Pripravit prezentaci',
description: 'Pro pondelni meeting',
energyLevel: 3,
createdAt: now,
updatedAt: now,
),
Task(
id: '3',
title: 'Uklid pokoje',
energyLevel: 2,
createdAt: now,
updatedAt: now,
),
Task(
id: '4',
title: 'Nakoupit veceri',
energyLevel: 1,
createdAt: now,
updatedAt: now,
),
];
}
}
@@ -0,0 +1,4 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
/// Provider for current user name.
final userNameProvider = Provider<String>((ref) => 'Zuf');
@@ -0,0 +1,204 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:google_fonts/google_fonts.dart';
import '../../../core/router/routes.dart';
import '../../../core/theme/kittie_colors.dart';
import '../../../shared/utils/czech_date.dart';
import '../../../shared/widgets/energy_bar.dart';
import '../../../shared/widgets/pet_bubble.dart';
import '../../../shared/widgets/streak_dots.dart';
import '../../../shared/widgets/task_card.dart';
import '../providers/pet_providers.dart';
import '../providers/task_providers.dart';
import '../providers/user_providers.dart';
/// Main Home Screen — date, greeting, energy bar, pet, streak, task list.
class TasksScreen extends ConsumerWidget {
const TasksScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final tasks = ref.watch(todayTasksProvider);
final petState = ref.watch(petStateProvider);
final userName = ref.watch(userNameProvider);
final pendingTasks = tasks.where((t) => !t.isCompleted).toList();
final completedTasks = tasks.where((t) => t.isCompleted).toList();
final pendingCount = pendingTasks.length;
return Scaffold(
body: SafeArea(
child: tasks.isEmpty
? _EmptyState(petType: petState.petType)
: SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(20, 16, 20, 100),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 1. Date header
Text(
czechDateHeader(DateTime.now()),
style: GoogleFonts.lexend(
fontSize: 12,
fontWeight: FontWeight.w500,
color: KittieColors.brownLight,
letterSpacing: 1.2,
),
),
const SizedBox(height: 4),
// 2. Greeting
Text(
'${czechGreeting()}, $userName',
style: GoogleFonts.lexend(
fontSize: 22,
fontWeight: FontWeight.w600,
color: KittieColors.brownDark,
),
),
const SizedBox(height: 20),
// 3. Energy bar
EnergyBar(energyLevel: petState.energyToday),
const SizedBox(height: 20),
// 4. Pet area
PetBubble(
petType: petState.petType,
mood: petState.mood,
message: _petMessage(petState.mood, petState.petName),
),
const SizedBox(height: 16),
// 5. Streak row
StreakDots(streakDays: petState.streakDays),
const SizedBox(height: 24),
// 6. Section header
Row(
children: [
Text(
'DNESNI UKOLY',
style: GoogleFonts.lexend(
fontSize: 12,
fontWeight: FontWeight.w600,
color: KittieColors.brownLight,
letterSpacing: 1.2,
),
),
const SizedBox(width: 8),
Container(
width: 22,
height: 22,
decoration: const BoxDecoration(
color: KittieColors.amber,
shape: BoxShape.circle,
),
child: Center(
child: Text(
'$pendingCount',
style: GoogleFonts.lexend(
fontSize: 11,
fontWeight: FontWeight.w700,
color: Colors.white,
),
),
),
),
],
),
const SizedBox(height: 12),
// 7. Task list — pending first, completed at bottom
...pendingTasks.map(
(task) => TaskCard(
task: task,
onComplete: () {
HapticFeedback.mediumImpact();
ref
.read(todayTasksProvider.notifier)
.completeTask(task.id);
ref
.read(petStateProvider.notifier)
.onTaskCompleted();
},
),
),
...completedTasks.map(
(task) => TaskCard(
task: task,
onComplete: () {
HapticFeedback.lightImpact();
ref
.read(todayTasksProvider.notifier)
.uncompleteTask(task.id);
},
),
),
],
),
),
),
// 8. FAB
floatingActionButton: FloatingActionButton(
onPressed: () => context.push(Routes.addTask),
child: const Icon(Icons.add),
),
);
}
static String _petMessage(String mood, String petName) {
return switch (mood) {
'happy' => '$petName je stastna! Jde ti to skvele \u{1F44F}',
'sad' => '$petName te podporuje. Zkus jeden ukol \u{1F495}',
'sleepy' => '$petName odpociva... Klid je taky dulezity \u{1F4A4}',
_ => '$petName te ceka! Co dnes zvladneme? \u{2728}',
};
}
}
class _EmptyState extends StatelessWidget {
final String petType;
const _EmptyState({required this.petType});
@override
Widget build(BuildContext context) {
final emoji = switch (petType) {
'dog' => '\u{1F436}',
'cat' => '\u{1F431}',
'capybara' => '\u{1F9AB}',
_ => '\u{1F431}',
};
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(emoji, style: const TextStyle(fontSize: 64)),
const SizedBox(height: 16),
Text(
'Zadne ukoly na dnes!',
style: GoogleFonts.lexend(
fontSize: 18,
fontWeight: FontWeight.w600,
color: KittieColors.brownLight,
),
),
const SizedBox(height: 8),
Text(
'Uzij si volny den \u{2615}',
style: GoogleFonts.lexend(
fontSize: 14,
color: KittieColors.brownLight,
),
),
],
),
);
}
}
+15 -112
View File
@@ -1,122 +1,25 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'core/router/app_router.dart';
import 'core/theme/kittie_theme.dart';
void main() {
runApp(const MyApp());
runApp(const ProviderScope(child: KittieApp()));
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
class KittieApp extends ConsumerWidget {
const KittieApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('You have pushed the button this many times:'),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
Widget build(BuildContext context, WidgetRef ref) {
final router = ref.watch(routerProvider);
return MaterialApp.router(
title: 'KittieMobile',
theme: KittieTheme.light,
routerConfig: router,
debugShowCheckedModeBanner: false,
);
}
}
+40
View File
@@ -0,0 +1,40 @@
const _czechDays = [
'PONDELI',
'UTERY',
'STREDA',
'CTVRTEK',
'PATEK',
'SOBOTA',
'NEDELE',
];
const _czechMonthsGenitive = [
'LEDNA',
'UNORA',
'BREZNA',
'DUBNA',
'KVETNA',
'CERVNA',
'CERVENCE',
'SRPNA',
'ZARI',
'RIJNA',
'LISTOPADU',
'PROSINCE',
];
/// Returns Czech date header like "STREDA, 17. BREZNA".
String czechDateHeader(DateTime date) {
final day = _czechDays[date.weekday - 1];
final month = _czechMonthsGenitive[date.month - 1];
return '$day, ${date.day}. $month';
}
/// Returns time-based Czech greeting.
String czechGreeting() {
final hour = DateTime.now().hour;
if (hour >= 5 && hour < 12) return 'Dobre rano';
if (hour >= 12 && hour < 18) return 'Dobry den';
if (hour >= 18 && hour < 22) return 'Dobry vecer';
return 'Dobrou noc';
}
+5 -23
View File
@@ -1,30 +1,12 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:kittie_mobile/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
testWidgets('KittieApp renders', (WidgetTester tester) async {
await tester.pumpWidget(const ProviderScope(child: KittieApp()));
await tester.pumpAndSettle();
expect(find.text('DNESNI UKOLY'), findsOneWidget);
});
}