feat: Home Screen — router, providers, TasksScreen scaffold
This commit is contained in:
@@ -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')),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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,36 @@
|
||||
/// Pure domain entity for pet companion state.
|
||||
class PetState {
|
||||
final String petName;
|
||||
final String petType;
|
||||
final int energyToday;
|
||||
final int streakDays;
|
||||
final int totalTasksDone;
|
||||
final String mood;
|
||||
|
||||
const PetState({
|
||||
this.petName = 'Kocicka',
|
||||
this.petType = 'cat',
|
||||
this.energyToday = 2,
|
||||
this.streakDays = 3,
|
||||
this.totalTasksDone = 0,
|
||||
this.mood = 'happy',
|
||||
});
|
||||
|
||||
PetState copyWith({
|
||||
String? petName,
|
||||
String? petType,
|
||||
int? energyToday,
|
||||
int? streakDays,
|
||||
int? totalTasksDone,
|
||||
String? mood,
|
||||
}) {
|
||||
return PetState(
|
||||
petName: petName ?? this.petName,
|
||||
petType: petType ?? this.petType,
|
||||
energyToday: energyToday ?? this.energyToday,
|
||||
streakDays: streakDays ?? this.streakDays,
|
||||
totalTasksDone: totalTasksDone ?? this.totalTasksDone,
|
||||
mood: mood ?? this.mood,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'task_status.dart';
|
||||
|
||||
/// Pure domain entity for a task.
|
||||
class Task {
|
||||
final String id;
|
||||
final String title;
|
||||
final String? description;
|
||||
final int energyLevel;
|
||||
final TaskStatus status;
|
||||
final DateTime? deadline;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
|
||||
const Task({
|
||||
required this.id,
|
||||
required this.title,
|
||||
this.description,
|
||||
this.energyLevel = 1,
|
||||
this.status = TaskStatus.pending,
|
||||
this.deadline,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
});
|
||||
|
||||
Task copyWith({
|
||||
String? id,
|
||||
String? title,
|
||||
String? description,
|
||||
int? energyLevel,
|
||||
TaskStatus? status,
|
||||
DateTime? deadline,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
}) {
|
||||
return Task(
|
||||
id: id ?? this.id,
|
||||
title: title ?? this.title,
|
||||
description: description ?? this.description,
|
||||
energyLevel: energyLevel ?? this.energyLevel,
|
||||
status: status ?? this.status,
|
||||
deadline: deadline ?? this.deadline,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
);
|
||||
}
|
||||
|
||||
bool get isCompleted => status == TaskStatus.done;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/// Status of a task in the KittieMobile app.
|
||||
enum TaskStatus {
|
||||
pending,
|
||||
done,
|
||||
snoozed,
|
||||
someday,
|
||||
archived,
|
||||
}
|
||||
@@ -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
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
import '../../core/theme/kittie_colors.dart';
|
||||
|
||||
/// Horizontal segmented energy bar showing today's energy level (1-3).
|
||||
class EnergyBar extends StatelessWidget {
|
||||
final int energyLevel;
|
||||
|
||||
const EnergyBar({super.key, required this.energyLevel});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'DNESNI ENERGIE',
|
||||
style: GoogleFonts.lexend(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: KittieColors.brownLight,
|
||||
letterSpacing: 1.2,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: List.generate(3, (index) {
|
||||
final segmentLevel = index + 1;
|
||||
final isActive = segmentLevel <= energyLevel;
|
||||
return Expanded(
|
||||
child: Container(
|
||||
height: 8,
|
||||
margin: EdgeInsets.only(right: index < 2 ? 4 : 0),
|
||||
decoration: BoxDecoration(
|
||||
color: isActive
|
||||
? _colorForLevel(segmentLevel)
|
||||
: KittieColors.creamDark,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
_labelForLevel(energyLevel),
|
||||
style: GoogleFonts.lexend(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: _colorForLevel(energyLevel),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
static Color _colorForLevel(int level) {
|
||||
return switch (level) {
|
||||
1 => KittieColors.energyLow,
|
||||
2 => KittieColors.energyMedium,
|
||||
3 => KittieColors.energyHigh,
|
||||
_ => KittieColors.brownLight,
|
||||
};
|
||||
}
|
||||
|
||||
static String _labelForLevel(int level) {
|
||||
return switch (level) {
|
||||
1 => 'Nizka',
|
||||
2 => 'Stredni',
|
||||
3 => 'Vysoka',
|
||||
_ => '',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
import '../../core/theme/kittie_colors.dart';
|
||||
|
||||
/// Pet display area with a motivational speech bubble.
|
||||
///
|
||||
/// Shows pet emoji placeholder (Rive animations will replace later)
|
||||
/// and a speech bubble with a contextual message.
|
||||
class PetBubble extends StatelessWidget {
|
||||
final String petType;
|
||||
final String mood;
|
||||
final String message;
|
||||
|
||||
const PetBubble({
|
||||
super.key,
|
||||
required this.petType,
|
||||
required this.mood,
|
||||
required this.message,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: KittieColors.creamDark,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: KittieColors.creamBorder),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// Pet avatar placeholder
|
||||
Container(
|
||||
width: 72,
|
||||
height: 72,
|
||||
decoration: BoxDecoration(
|
||||
color: KittieColors.cream,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: KittieColors.creamBorder, width: 2),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
_petEmoji,
|
||||
style: const TextStyle(fontSize: 36),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// Speech bubble
|
||||
Expanded(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: KittieColors.cream,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: KittieColors.creamBorder),
|
||||
),
|
||||
child: Text(
|
||||
message,
|
||||
style: GoogleFonts.lexend(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: KittieColors.brown,
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String get _petEmoji {
|
||||
return switch (petType) {
|
||||
'dog' => '\u{1F436}',
|
||||
'cat' => '\u{1F431}',
|
||||
'capybara' => '\u{1F9AB}',
|
||||
_ => '\u{1F431}',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
import '../../core/constants/app_constants.dart';
|
||||
import '../../core/theme/kittie_colors.dart';
|
||||
|
||||
/// Row of dots showing current streak days (max 7).
|
||||
class StreakDots extends StatelessWidget {
|
||||
final int streakDays;
|
||||
|
||||
const StreakDots({super.key, required this.streakDays});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
const Icon(Icons.local_fire_department, color: KittieColors.orange, size: 20),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'$streakDays dni',
|
||||
style: GoogleFonts.lexend(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: KittieColors.brown,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
...List.generate(AppConstants.maxStreakDisplay, (index) {
|
||||
final isFilled = index < streakDays;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 4),
|
||||
child: Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: isFilled ? KittieColors.orange : KittieColors.creamDark,
|
||||
border: isFilled
|
||||
? null
|
||||
: Border.all(color: KittieColors.creamBorder),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
import '../../core/constants/app_constants.dart';
|
||||
import '../../core/theme/kittie_colors.dart';
|
||||
import '../../domain/entities/task.dart';
|
||||
|
||||
/// Card widget for displaying a single task in the list.
|
||||
class TaskCard extends StatelessWidget {
|
||||
final Task task;
|
||||
final VoidCallback onComplete;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const TaskCard({
|
||||
super.key,
|
||||
required this.task,
|
||||
required this.onComplete,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedOpacity(
|
||||
opacity: task.isCompleted ? 0.5 : 1.0,
|
||||
duration: AppConstants.animationFast,
|
||||
child: GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: task.isCompleted ? KittieColors.creamDark : KittieColors.cream,
|
||||
borderRadius: BorderRadius.circular(AppConstants.cardBorderRadius),
|
||||
border: Border.all(color: KittieColors.creamBorder),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// Completion checkbox
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
HapticFeedback.lightImpact();
|
||||
onComplete();
|
||||
},
|
||||
child: Container(
|
||||
width: 28,
|
||||
height: 28,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: task.isCompleted
|
||||
? KittieColors.sageGreen
|
||||
: Colors.transparent,
|
||||
border: Border.all(
|
||||
color: task.isCompleted
|
||||
? KittieColors.sageGreen
|
||||
: KittieColors.brownLight,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: task.isCompleted
|
||||
? const Icon(Icons.check, size: 16, color: Colors.white)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// Task content
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
task.title,
|
||||
style: GoogleFonts.lexend(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: KittieColors.brownDark,
|
||||
decoration: task.isCompleted
|
||||
? TextDecoration.lineThrough
|
||||
: null,
|
||||
decorationColor: KittieColors.brownLight,
|
||||
),
|
||||
),
|
||||
if (task.description != null) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
task.description!,
|
||||
style: GoogleFonts.lexend(
|
||||
fontSize: 12,
|
||||
color: KittieColors.brownLight,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// Energy level badge
|
||||
_EnergyBadge(level: task.energyLevel),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _EnergyBadge extends StatelessWidget {
|
||||
final int level;
|
||||
|
||||
const _EnergyBadge({required this.level});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = switch (level) {
|
||||
1 => KittieColors.energyLow,
|
||||
2 => KittieColors.energyMedium,
|
||||
3 => KittieColors.energyHigh,
|
||||
_ => KittieColors.brownLight,
|
||||
};
|
||||
|
||||
return Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.15),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'$level',
|
||||
style: GoogleFonts.lexend(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+5
-23
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user