feat: Pet Stats Screen + Zen Mode + Profile scaffolding

This commit is contained in:
TrochtaOndrej
2026-03-18 04:37:42 +01:00
parent 03e1ab1d24
commit 4147cb1e8b
19 changed files with 1273 additions and 133 deletions
+66
View File
@@ -0,0 +1,66 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../features/tasks/screens/tasks_screen.dart';
import '../../features/tasks/screens/pet_screen.dart';
import '../../features/zen_mode/screens/zen_screen.dart';
import '../../shared/widgets/profile_screen.dart';
import '../../shared/widgets/app_shell.dart';
/// Route name constants.
abstract final class Routes {
static const String tasks = '/tasks';
static const String pet = '/pet';
static const String zen = '/zen';
static const String profile = '/profile';
}
final appRouterProvider = Provider<GoRouter>((ref) {
return GoRouter(
initialLocation: Routes.tasks,
routes: [
StatefulShellRoute.indexedStack(
builder: (context, state, navigationShell) {
return AppShell(navigationShell: navigationShell);
},
branches: [
StatefulShellBranch(
routes: [
GoRoute(
path: Routes.tasks,
pageBuilder: (context, state) => const NoTransitionPage(
child: TasksScreen(),
),
),
],
),
StatefulShellBranch(
routes: [
GoRoute(
path: Routes.pet,
pageBuilder: (context, state) => const NoTransitionPage(
child: PetScreen(),
),
),
],
),
StatefulShellBranch(
routes: [
GoRoute(
path: Routes.profile,
pageBuilder: (context, state) => const NoTransitionPage(
child: ProfileScreen(),
),
),
],
),
],
),
// Zen mode — outside shell, no bottom nav
GoRoute(
path: Routes.zen,
builder: (context, state) => const ZenScreen(),
),
],
);
});
+36
View File
@@ -0,0 +1,36 @@
/// Pure domain entity for pet state.
class PetStateEntity {
final int id;
final int userId;
final int? energyToday;
final int streakDays;
final int totalTasksDone;
final String unlockedItems;
const PetStateEntity({
required this.id,
required this.userId,
this.energyToday,
this.streakDays = 0,
this.totalTasksDone = 0,
this.unlockedItems = '',
});
PetStateEntity copyWith({
int? id,
int? userId,
int? energyToday,
int? streakDays,
int? totalTasksDone,
String? unlockedItems,
}) {
return PetStateEntity(
id: id ?? this.id,
userId: userId ?? this.userId,
energyToday: energyToday ?? this.energyToday,
streakDays: streakDays ?? this.streakDays,
totalTasksDone: totalTasksDone ?? this.totalTasksDone,
unlockedItems: unlockedItems ?? this.unlockedItems,
);
}
}
+28
View File
@@ -0,0 +1,28 @@
/// Pet types available in KittieMobile.
enum PetType {
dog,
cat,
capybara;
/// Parses a string to [PetType], defaults to [cat].
static PetType fromString(String value) {
return PetType.values.firstWhere(
(type) => type.name == value,
orElse: () => PetType.cat,
);
}
/// Display emoji for each pet type.
String get emoji => switch (this) {
PetType.dog => '\u{1F436}',
PetType.cat => '\u{1F431}',
PetType.capybara => '\u{1F9AB}',
};
/// Czech label for each pet type.
String get label => switch (this) {
PetType.dog => 'Pejsek',
PetType.cat => 'Kocicka',
PetType.capybara => 'Kapybara',
};
}
+58
View File
@@ -0,0 +1,58 @@
import 'task_status.dart';
/// Pure domain entity for a task.
class TaskEntity {
final int id;
final int userId;
final String title;
final String? description;
final int energyLevel;
final TaskStatus status;
final bool isSelfCare;
final DateTime? deadline;
final int sortOrder;
final DateTime createdAt;
final DateTime updatedAt;
const TaskEntity({
required this.id,
required this.userId,
required this.title,
this.description,
this.energyLevel = 2,
this.status = TaskStatus.pending,
this.isSelfCare = false,
this.deadline,
this.sortOrder = 0,
required this.createdAt,
required this.updatedAt,
});
TaskEntity copyWith({
int? id,
int? userId,
String? title,
String? description,
int? energyLevel,
TaskStatus? status,
bool? isSelfCare,
DateTime? deadline,
int? sortOrder,
DateTime? createdAt,
DateTime? updatedAt,
}) {
return TaskEntity(
id: id ?? this.id,
userId: userId ?? this.userId,
title: title ?? this.title,
description: description ?? this.description,
energyLevel: energyLevel ?? this.energyLevel,
status: status ?? this.status,
isSelfCare: isSelfCare ?? this.isSelfCare,
deadline: deadline ?? this.deadline,
sortOrder: sortOrder ?? this.sortOrder,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
);
}
}
+16
View File
@@ -0,0 +1,16 @@
/// Task lifecycle states.
enum TaskStatus {
pending,
done,
snoozed,
someday,
archived;
/// Parses a string to [TaskStatus], defaults to [pending].
static TaskStatus fromString(String value) {
return TaskStatus.values.firstWhere(
(status) => status.name == value,
orElse: () => TaskStatus.pending,
);
}
}
+30
View File
@@ -0,0 +1,30 @@
import 'pet_type.dart';
/// Pure domain entity for a user.
class UserEntity {
final int id;
final String name;
final PetType petType;
final String petName;
const UserEntity({
required this.id,
this.name = 'Friend',
this.petType = PetType.cat,
this.petName = 'Yoshi',
});
UserEntity copyWith({
int? id,
String? name,
PetType? petType,
String? petName,
}) {
return UserEntity(
id: id ?? this.id,
name: name ?? this.name,
petType: petType ?? this.petType,
petName: petName ?? this.petName,
);
}
}
@@ -0,0 +1,75 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../domain/entities/pet_state_entity.dart';
import '../../../domain/entities/pet_type.dart';
import '../../../domain/entities/user_entity.dart';
/// Pet mood states.
enum PetMood {
happy,
neutral,
sad;
String get emoji => switch (this) {
PetMood.happy => '\u{1F60A}',
PetMood.neutral => '\u{1F610}',
PetMood.sad => '\u{1F622}',
};
}
// ── User ──
class UserNotifier extends Notifier<UserEntity> {
@override
UserEntity build() => const UserEntity(
id: 1,
name: 'Friend',
petType: PetType.cat,
petName: 'Yoshi',
);
void updateName(String name) => state = state.copyWith(name: name);
void updatePetName(String petName) =>
state = state.copyWith(petName: petName);
}
final userProvider =
NotifierProvider<UserNotifier, UserEntity>(UserNotifier.new);
// ── Pet state ──
class PetStateNotifier extends Notifier<PetStateEntity> {
@override
PetStateEntity build() => const PetStateEntity(
id: 1,
userId: 1,
energyToday: 2,
streakDays: 3,
totalTasksDone: 12,
unlockedItems: 'masle,pelisek',
);
void incrementTasksDone() {
state = state.copyWith(totalTasksDone: state.totalTasksDone + 1);
}
}
final petStateProvider =
NotifierProvider<PetStateNotifier, PetStateEntity>(PetStateNotifier.new);
// ── Derived providers ──
/// Pet mood derived from pet state.
final petMoodProvider = Provider<PetMood>((ref) {
final pet = ref.watch(petStateProvider);
if (pet.streakDays >= 3 || pet.totalTasksDone >= 5) return PetMood.happy;
if (pet.totalTasksDone == 0) return PetMood.sad;
return PetMood.neutral;
});
/// Pet level = totalTasksDone / 15 + 1, max 10.
final petLevelProvider = Provider<int>((ref) {
final pet = ref.watch(petStateProvider);
final level = pet.totalTasksDone ~/ 15 + 1;
return level.clamp(1, 10);
});
@@ -0,0 +1,116 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../domain/entities/task_entity.dart';
import '../../../domain/entities/task_status.dart';
/// Notifier managing the task list.
class TasksNotifier extends Notifier<List<TaskEntity>> {
@override
List<TaskEntity> build() => _sampleTasks;
void completeTask(int id) {
state = [
for (final task in state)
if (task.id == id)
task.copyWith(
status: TaskStatus.done,
updatedAt: DateTime.now(),
)
else
task,
];
}
void skipTask(int id) {
final skipped = state.firstWhere((t) => t.id == id);
state = [
...state.where((t) => t.id != id),
skipped.copyWith(sortOrder: skipped.sortOrder + 100),
];
}
}
/// All tasks.
final tasksProvider =
NotifierProvider<TasksNotifier, List<TaskEntity>>(TasksNotifier.new);
/// Pending tasks only, ordered by sort order.
final pendingTasksProvider = Provider<List<TaskEntity>>((ref) {
final tasks = ref.watch(tasksProvider);
return tasks
.where((t) => t.status == TaskStatus.pending)
.toList()
..sort((a, b) => a.sortOrder.compareTo(b.sortOrder));
});
/// Next zen task: first pending task sorted by energy level (lowest first).
final nextZenTaskProvider = Provider<TaskEntity?>((ref) {
final pending = ref.watch(pendingTasksProvider);
if (pending.isEmpty) return null;
final sorted = [...pending]
..sort((a, b) => a.energyLevel.compareTo(b.energyLevel));
return sorted.first;
});
/// Count of completed self-care tasks.
final selfCareCountProvider = Provider<int>((ref) {
final tasks = ref.watch(tasksProvider);
return tasks
.where((t) => t.isSelfCare && t.status == TaskStatus.done)
.length;
});
// — Sample data for development —
final _now = DateTime.now();
final _sampleTasks = <TaskEntity>[
TaskEntity(
id: 1,
userId: 1,
title: 'Nakoupit potraviny',
energyLevel: 1,
sortOrder: 0,
createdAt: _now,
updatedAt: _now,
),
TaskEntity(
id: 2,
userId: 1,
title: 'Udelat prezentaci',
energyLevel: 3,
sortOrder: 1,
createdAt: _now,
updatedAt: _now,
),
TaskEntity(
id: 3,
userId: 1,
title: 'Protahnout se',
energyLevel: 1,
isSelfCare: true,
sortOrder: 2,
createdAt: _now,
updatedAt: _now,
),
TaskEntity(
id: 4,
userId: 1,
title: 'Napsat email klientovi',
energyLevel: 2,
sortOrder: 3,
createdAt: _now,
updatedAt: _now,
),
TaskEntity(
id: 5,
userId: 1,
title: 'Meditace',
energyLevel: 1,
isSelfCare: true,
status: TaskStatus.done,
sortOrder: 4,
createdAt: _now,
updatedAt: _now,
),
];
+274
View File
@@ -0,0 +1,274 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../core/theme/kittie_colors.dart';
import '../../../core/theme/kittie_typography.dart';
import '../providers/pet_providers.dart';
import '../providers/task_providers.dart';
/// Pet companion screen — stats, avatar, unlocked items.
class PetScreen extends ConsumerWidget {
const PetScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final user = ref.watch(userProvider);
final petState = ref.watch(petStateProvider);
final mood = ref.watch(petMoodProvider);
final level = ref.watch(petLevelProvider);
final selfCareCount = ref.watch(selfCareCountProvider);
final unlocked = petState.unlockedItems.isEmpty
? <String>[]
: petState.unlockedItems.split(',');
return Scaffold(
backgroundColor: KittieColors.cream,
body: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
child: Column(
children: [
// Pet name header
Text(
user.petName,
style: KittieTypography.h1.copyWith(fontSize: 24),
),
const SizedBox(height: 4),
Text(
'Tvuj spolecnik — ${user.petType.label}',
style: KittieTypography.bodyMedium.copyWith(
color: KittieColors.brownLight,
),
),
const SizedBox(height: 24),
// Large circular avatar with mood badge
Stack(
clipBehavior: Clip.none,
children: [
Container(
width: 130,
height: 130,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: KittieColors.creamDark,
border: Border.all(
color: KittieColors.creamBorder,
width: 3,
),
),
child: Center(
child: Text(
user.petType.emoji,
style: const TextStyle(fontSize: 64),
),
),
),
Positioned(
bottom: 0,
right: 0,
child: Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: _moodColor(mood),
shape: BoxShape.circle,
border: Border.all(
color: KittieColors.cream,
width: 2,
),
),
child: Center(
child: Text(
mood.emoji,
style: const TextStyle(fontSize: 18),
),
),
),
),
],
),
const SizedBox(height: 32),
// Stats grid 2×2
GridView.count(
crossAxisCount: 2,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
mainAxisSpacing: 12,
crossAxisSpacing: 12,
childAspectRatio: 1.4,
children: [
_StatTile(
icon: Icons.local_fire_department_rounded,
label: 'Streak',
value: '${petState.streakDays} dni',
color: KittieColors.orange,
),
_StatTile(
icon: Icons.check_circle_rounded,
label: 'Hotove ukoly',
value: '${petState.totalTasksDone}',
color: KittieColors.sageGreen,
),
_StatTile(
icon: Icons.favorite_rounded,
label: 'Pece o sebe',
value: '$selfCareCount',
color: KittieColors.purple,
),
_StatTile(
icon: Icons.star_rounded,
label: 'Uroven',
value: '$level',
color: KittieColors.amber,
),
],
),
const SizedBox(height: 32),
// Unlocked items header
Align(
alignment: Alignment.centerLeft,
child: Text('Odemcene predmety',
style: KittieTypography.h3),
),
const SizedBox(height: 12),
// Horizontal scroll of items
SizedBox(
height: 100,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
_ItemCard(
name: 'Masle',
icon: Icons.catching_pokemon_rounded,
unlocked: unlocked.contains('masle'),
),
_ItemCard(
name: 'Pelisek',
icon: Icons.bed_rounded,
unlocked: unlocked.contains('pelisek'),
),
_ItemCard(
name: 'Koruna',
icon: Icons.auto_awesome_rounded,
unlocked: unlocked.contains('koruna'),
),
_ItemCard(
name: 'Kridla',
icon: Icons.flight_rounded,
unlocked: unlocked.contains('kridla'),
),
],
),
),
const SizedBox(height: 24),
],
),
),
),
);
}
Color _moodColor(PetMood mood) => switch (mood) {
PetMood.happy => KittieColors.sageGreen,
PetMood.neutral => KittieColors.amber,
PetMood.sad => KittieColors.red,
};
}
// ── Private widgets ──
class _StatTile extends StatelessWidget {
final IconData icon;
final String label;
final String value;
final Color color;
const _StatTile({
required this.icon,
required this.label,
required this.value,
required this.color,
});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: color.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(16),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, color: color, size: 24),
const SizedBox(height: 8),
Text(
value,
style: KittieTypography.h2.copyWith(color: color),
),
Text(
label,
style: KittieTypography.bodySmall.copyWith(color: color),
),
],
),
);
}
}
class _ItemCard extends StatelessWidget {
final String name;
final IconData icon;
final bool unlocked;
const _ItemCard({
required this.name,
required this.icon,
required this.unlocked,
});
@override
Widget build(BuildContext context) {
return Opacity(
opacity: unlocked ? 1.0 : 0.35,
child: Container(
width: 80,
margin: const EdgeInsets.only(right: 12),
decoration: BoxDecoration(
color: KittieColors.creamDark,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: KittieColors.creamBorder),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
icon,
size: 32,
color: unlocked ? KittieColors.amber : KittieColors.brownLight,
),
const SizedBox(height: 6),
Text(
name,
style: KittieTypography.labelSmall,
textAlign: TextAlign.center,
),
if (!unlocked)
Icon(
Icons.lock_rounded,
size: 12,
color: KittieColors.brownLight,
),
],
),
),
);
}
}
@@ -0,0 +1,20 @@
import 'package:flutter/material.dart';
import '../../../core/theme/kittie_colors.dart';
import '../../../core/theme/kittie_typography.dart';
/// Main task list screen (stub — full implementation in a later branch).
class TasksScreen extends StatelessWidget {
const TasksScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: KittieColors.cream,
appBar: AppBar(title: Text('Ukoly', style: KittieTypography.h2)),
body: const Center(
child: Text('Tasks'),
),
);
}
}
@@ -0,0 +1,137 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../../core/theme/kittie_colors.dart';
import '../../../core/theme/kittie_typography.dart';
import '../../../shared/widgets/energy_badge.dart';
import '../../../domain/entities/task_entity.dart';
import '../../tasks/providers/task_providers.dart';
import '../../tasks/providers/pet_providers.dart';
/// Distraction-free single-task view.
///
/// Shows next pending task (lowest energy first).
/// No bottom nav — full screen with back button.
class ZenScreen extends ConsumerWidget {
const ZenScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final task = ref.watch(nextZenTaskProvider);
return Scaffold(
backgroundColor: KittieColors.creamDark,
body: SafeArea(
child: Column(
children: [
// Back button
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.only(left: 8, top: 8),
child: IconButton(
icon: const Icon(Icons.arrow_back_rounded),
color: KittieColors.brown,
onPressed: () => context.pop(),
),
),
),
// Main content
Expanded(
child: Center(
child: task == null
? _buildEmpty()
: _buildTask(context, ref, task),
),
),
// Action buttons
if (task != null)
Padding(
padding: const EdgeInsets.fromLTRB(24, 0, 24, 32),
child: Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () {
ref.read(tasksProvider.notifier).completeTask(task.id);
ref.read(petStateProvider.notifier).incrementTasksDone();
},
style: ElevatedButton.styleFrom(
backgroundColor: KittieColors.sageGreen,
foregroundColor: Colors.white,
minimumSize: const Size(0, 52),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
),
child: Text('Hotovo',
style: KittieTypography.labelLarge
.copyWith(color: Colors.white)),
),
),
const SizedBox(width: 12),
Expanded(
child: TextButton(
onPressed: () {
ref.read(tasksProvider.notifier).skipTask(task.id);
},
style: TextButton.styleFrom(
foregroundColor: KittieColors.brownLight,
minimumSize: const Size(0, 52),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
side: const BorderSide(
color: KittieColors.creamBorder,
),
),
),
child: Text('Preskocit',
style: KittieTypography.labelLarge
.copyWith(color: KittieColors.brownLight)),
),
),
],
),
),
],
),
),
);
}
Widget _buildEmpty() {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('\u{2728}', style: TextStyle(fontSize: 48)),
const SizedBox(height: 16),
Text(
'Vse hotovo.\nOdpocivej.',
textAlign: TextAlign.center,
style: KittieTypography.h2.copyWith(color: KittieColors.brown),
),
],
);
}
Widget _buildTask(BuildContext context, WidgetRef ref, TaskEntity task) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
task.title,
textAlign: TextAlign.center,
style: KittieTypography.h1.copyWith(fontSize: 28),
),
const SizedBox(height: 16),
EnergyBadge(energyLevel: task.energyLevel),
],
),
);
}
}
+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(appRouterProvider);
return MaterialApp.router(
title: 'KittieMobile',
theme: KittieTheme.light,
routerConfig: router,
debugShowCheckedModeBanner: false,
);
}
}
View File
+97
View File
@@ -0,0 +1,97 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../core/theme/kittie_colors.dart';
import '../../core/theme/kittie_typography.dart';
import '../../core/constants/app_constants.dart';
/// Bottom navigation shell wrapping the main tabs.
class AppShell extends StatelessWidget {
final StatefulNavigationShell navigationShell;
const AppShell({super.key, required this.navigationShell});
@override
Widget build(BuildContext context) {
return Scaffold(
body: navigationShell,
bottomNavigationBar: Container(
height: AppConstants.bottomNavHeight,
decoration: const BoxDecoration(
color: KittieColors.cream,
border: Border(
top: BorderSide(color: KittieColors.creamBorder, width: 0.5),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_NavItem(
icon: Icons.grid_view_rounded,
label: 'ukoly',
isActive: navigationShell.currentIndex == 0,
onTap: () => navigationShell.goBranch(0),
),
_NavItem(
icon: Icons.pets_rounded,
label: 'mazlicek',
isActive: navigationShell.currentIndex == 1,
onTap: () => navigationShell.goBranch(1),
),
_NavItem(
icon: Icons.person_rounded,
label: 'profil',
isActive: navigationShell.currentIndex == 2,
onTap: () => navigationShell.goBranch(2),
),
],
),
),
);
}
}
class _NavItem extends StatelessWidget {
final IconData icon;
final String label;
final bool isActive;
final VoidCallback onTap;
const _NavItem({
required this.icon,
required this.label,
required this.isActive,
required this.onTap,
});
@override
Widget build(BuildContext context) {
final color = isActive ? KittieColors.brown : KittieColors.brownLight;
return GestureDetector(
onTap: onTap,
behavior: HitTestBehavior.opaque,
child: SizedBox(
width: 64,
height: AppConstants.bottomNavHeight,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, color: color, size: 24),
const SizedBox(height: 2),
Text(label, style: KittieTypography.labelSmall.copyWith(color: color)),
const SizedBox(height: 4),
if (isActive)
Container(
width: 4,
height: 4,
decoration: const BoxDecoration(
color: KittieColors.amber,
shape: BoxShape.circle,
),
),
],
),
),
);
}
}
+37
View File
@@ -0,0 +1,37 @@
import 'package:flutter/material.dart';
import '../../core/theme/kittie_colors.dart';
import '../../core/theme/kittie_typography.dart';
/// Compact pill showing the energy level with icon and Czech label.
class EnergyBadge extends StatelessWidget {
final int energyLevel;
const EnergyBadge({super.key, required this.energyLevel});
@override
Widget build(BuildContext context) {
final (icon, label, fg, bg) = switch (energyLevel) {
1 => (Icons.eco_rounded, 'Lehke', KittieColors.sageGreen, KittieColors.greenLight),
3 => (Icons.local_fire_department_rounded, 'Narocne', KittieColors.red, KittieColors.redLight),
_ => (Icons.wb_sunny_rounded, 'Stredni', KittieColors.orange, KittieColors.orangeLight),
};
return Container(
height: 24,
padding: const EdgeInsets.symmetric(horizontal: 8),
decoration: BoxDecoration(
color: bg,
borderRadius: BorderRadius.circular(12),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(icon, size: 14, color: fg),
const SizedBox(width: 4),
Text(label, style: KittieTypography.labelSmall.copyWith(color: fg)),
],
),
);
}
}
+260
View File
@@ -0,0 +1,260 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/theme/kittie_colors.dart';
import '../../core/theme/kittie_typography.dart';
import '../../features/tasks/providers/pet_providers.dart';
/// User profile screen — name, pet info, stats, export.
class ProfileScreen extends ConsumerWidget {
const ProfileScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final user = ref.watch(userProvider);
final petState = ref.watch(petStateProvider);
final level = ref.watch(petLevelProvider);
return Scaffold(
backgroundColor: KittieColors.cream,
body: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Profil', style: KittieTypography.h2),
const SizedBox(height: 24),
// User name
_EditableRow(
label: 'Jmeno',
value: user.name,
onEdit: () => _showEditDialog(
context,
title: 'Upravit jmeno',
initialValue: user.name,
onSave: (v) => ref.read(userProvider.notifier).updateName(v),
),
),
const SizedBox(height: 16),
// Pet name
_EditableRow(
label: 'Jmeno mazlicka',
value: user.petName,
onEdit: () => _showEditDialog(
context,
title: 'Upravit jmeno mazlicka',
initialValue: user.petName,
onSave: (v) =>
ref.read(userProvider.notifier).updatePetName(v),
),
),
const SizedBox(height: 16),
// Pet type
_InfoRow(label: 'Typ mazlicka', value: user.petType.label),
const SizedBox(height: 32),
// Stats summary
Text('Statistiky', style: KittieTypography.h3),
const SizedBox(height: 12),
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: KittieColors.creamDark,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: KittieColors.creamBorder),
),
child: Column(
children: [
_StatRow(
icon: Icons.local_fire_department_rounded,
label: 'Streak',
value: '${petState.streakDays} dni',
color: KittieColors.orange,
),
const Divider(color: KittieColors.creamBorder, height: 24),
_StatRow(
icon: Icons.check_circle_rounded,
label: 'Hotove ukoly',
value: '${petState.totalTasksDone}',
color: KittieColors.sageGreen,
),
const Divider(color: KittieColors.creamBorder, height: 24),
_StatRow(
icon: Icons.star_rounded,
label: 'Uroven mazlicka',
value: '$level',
color: KittieColors.amber,
),
],
),
),
const SizedBox(height: 32),
// Export button
SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Pripravujeme')),
);
},
icon: const Icon(Icons.download_rounded),
label: Text('Exportovat data',
style: KittieTypography.labelLarge),
style: OutlinedButton.styleFrom(
foregroundColor: KittieColors.brown,
side: const BorderSide(color: KittieColors.creamBorder),
minimumSize: const Size(0, 48),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
),
const SizedBox(height: 48),
// Version
Center(
child: Text(
'KittieMobile v1.0.0',
style: KittieTypography.bodySmall.copyWith(
color: KittieColors.brownLight,
),
),
),
const SizedBox(height: 24),
],
),
),
),
);
}
void _showEditDialog(
BuildContext context, {
required String title,
required String initialValue,
required ValueChanged<String> onSave,
}) {
final controller = TextEditingController(text: initialValue);
showDialog(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: KittieColors.cream,
title: Text(title, style: KittieTypography.h3),
content: TextField(
controller: controller,
autofocus: true,
style: KittieTypography.bodyLarge,
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('Zrusit'),
),
ElevatedButton(
onPressed: () {
final text = controller.text.trim();
if (text.isNotEmpty) onSave(text);
Navigator.pop(ctx);
},
child: const Text('Ulozit'),
),
],
),
);
}
}
// ── Private helper widgets ──
class _EditableRow extends StatelessWidget {
final String label;
final String value;
final VoidCallback onEdit;
const _EditableRow({
required this.label,
required this.value,
required this.onEdit,
});
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label,
style: KittieTypography.labelMedium
.copyWith(color: KittieColors.brownLight)),
const SizedBox(height: 4),
Text(value, style: KittieTypography.bodyLarge),
],
),
),
IconButton(
icon: const Icon(Icons.edit_rounded, size: 20),
color: KittieColors.brownLight,
onPressed: onEdit,
),
],
);
}
}
class _InfoRow extends StatelessWidget {
final String label;
final String value;
const _InfoRow({required this.label, required this.value});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label,
style: KittieTypography.labelMedium
.copyWith(color: KittieColors.brownLight)),
const SizedBox(height: 4),
Text(value, style: KittieTypography.bodyLarge),
],
);
}
}
class _StatRow extends StatelessWidget {
final IconData icon;
final String label;
final String value;
final Color color;
const _StatRow({
required this.icon,
required this.label,
required this.value,
required this.color,
});
@override
Widget build(BuildContext context) {
return Row(
children: [
Icon(icon, color: color, size: 20),
const SizedBox(width: 12),
Expanded(child: Text(label, style: KittieTypography.bodyMedium)),
Text(value,
style: KittieTypography.labelLarge.copyWith(color: color)),
],
);
}
}
+8 -21
View File
@@ -1,30 +1,17 @@
// 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());
testWidgets('KittieApp smoke test', (WidgetTester tester) async {
await tester.pumpWidget(
const ProviderScope(child: KittieApp()),
);
await tester.pumpAndSettle();
// 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);
// App renders without crashing
expect(find.byType(MaterialApp), findsOneWidget);
});
}