Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .github/assets/autism-level-after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/assets/autism-level-before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 32 additions & 4 deletions patient/lib/presentation/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:patient/presentation/reports/report_screen.dart'; // Import the
import 'package:patient/presentation/notification/updates_screen.dart';
import 'package:patient/presentation/games/games_screen.dart';
import 'package:patient/presentation/profile/profile_screen.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

import '../../gen/assets.gen.dart';

Expand All @@ -28,6 +29,8 @@ class HomeScreen extends StatefulWidget {
class _HomeScreenState extends State<HomeScreen> {
int _selectedIndex = 0;
late List<Widget> _screens;
static const int _maxAutismLevel = 18;
double _autismLevel = 0;

@override
void initState() {
Expand All @@ -39,6 +42,31 @@ class _HomeScreenState extends State<HomeScreen> {
UpdatesScreen(),
const ProfileScreen(),
];
_fetchAutismLevel();
}

Future<void> _fetchAutismLevel() async {
try {
final currentUser = Supabase.instance.client.auth.currentUser;
if (currentUser == null) return;

final response = await Supabase.instance.client
.from('patient')
.select('autism_level')
.eq('id', currentUser.id)
.maybeSingle();

final rawLevel = response?['autism_level'];
final level = rawLevel is num ? rawLevel.toDouble() : 0;

if (!mounted) return;
setState(() {
_autismLevel = level.clamp(0, _maxAutismLevel.toDouble()).toDouble();
_screens[0] = _buildHomeContent();
});
} catch (_) {
// Keep fallback value when backend field is unavailable.
}
}

@override
Expand Down Expand Up @@ -138,7 +166,7 @@ class _HomeScreenState extends State<HomeScreen> {
Expanded(
child: ListView(
children: [
const LevelIndicator(currentLevel: 5, maxLevel: 18),
LevelIndicator(currentLevel: _autismLevel, maxLevel: _maxAutismLevel),
const SizedBox(height: 15),
// Using the reusable TherapyGoalCard three times
GestureDetector(
Expand All @@ -153,7 +181,7 @@ class _HomeScreenState extends State<HomeScreen> {
title: 'Therapy',
subtitle: 'Goals',
illustration: Assets.illustrations.i9nGoals,
backgroundColor: Color(0xFFF9F3E3),
backgroundColor: const Color(0xFFF9F3E3),
),
),
const SizedBox(height: 15),
Expand All @@ -171,7 +199,7 @@ class _HomeScreenState extends State<HomeScreen> {
title: 'Daily',
subtitle: 'Activities',
illustration: Assets.illustrations.i9nActivities,
backgroundColor: Color(0xFFFEF4F0),
backgroundColor: const Color(0xFFFEF4F0),
imageOnLeft: true,
),
),
Expand All @@ -182,7 +210,7 @@ class _HomeScreenState extends State<HomeScreen> {
title: 'Development',
subtitle: 'Milestones',
illustration: Assets.illustrations.i9nMilestones,
backgroundColor: Color(0xFFF5FAF4),
backgroundColor: const Color(0xFFF5FAF4),
),
const SizedBox(height: 15),
// Games Card
Expand Down
112 changes: 67 additions & 45 deletions patient/lib/presentation/home/widgets/home_screen_slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class LevelIndicator extends StatelessWidget {

@override
Widget build(BuildContext context) {
final safeMaxLevel = maxLevel <= 0 ? 1 : maxLevel;
final clampedLevel = currentLevel.clamp(0, safeMaxLevel.toDouble());

return Card(
elevation: 0,
color: const Color(0xFFCB6CE6),
Expand All @@ -35,59 +38,78 @@ class LevelIndicator extends StatelessWidget {
Row(
children: [
Expanded(
child: Stack(
alignment: Alignment.centerLeft,
children: [
// Slider track
Container(
height: 40, // Increased height for better visibility
decoration: BoxDecoration(
color: const Color(0xFFCB6CE6),
borderRadius: BorderRadius.circular(10),
),
),
// Tick marks
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: List.generate(
maxLevel, // Number of divisions based on max level
(index) => Container(
height: index % 2 == 0
? 20
: 15, // Alternating heights for ticks
width: 2,
color: Colors.white.withOpacity(0.7),
),
),
),
// Current level indicator (triangle)
// Current level indicator (triangle with text above)
Positioned(
left: (currentLevel / (maxLevel)) *
(MediaQuery.of(context).size.width * 0.8 -
25), // Adjust for better alignment
child: Column(
child: LayoutBuilder(
builder: (context, constraints) {
const indicatorWidth = 40.0;
const tickTop = 44.0;
const halfIndicator = indicatorWidth / 2;
final trackWidth = constraints.maxWidth;
final ratio = clampedLevel / safeMaxLevel;
final indicatorLeft = ratio * (trackWidth - indicatorWidth);

return SizedBox(
height: 84,
child: Stack(
children: [
Text(
currentLevel.toStringAsFixed(0),
style: const TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: Colors.white,
Positioned(
left: 0,
right: 0,
top: tickTop,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: halfIndicator),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: List.generate(
safeMaxLevel + 1,
(index) => Container(
height: index % 2 == 0 ? 20 : 15,
width: 2,
color: Colors.white.withValues(alpha: 0.7),
),
),
),
),
),
const SizedBox(height: 5),
CustomPaint(
size: const Size(20, 20),
painter: TrianglePainter(),
Positioned(
left: indicatorLeft,
top: 0,
child: SizedBox(
width: indicatorWidth,
height: tickTop + 20,
child: Stack(
children: [
Positioned(
top: 0,
left: 0,
right: 0,
child: Text(
clampedLevel.toStringAsFixed(0),
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
Positioned(
top: tickTop,
left: 10,
child: CustomPaint(
size: const Size(20, 20),
painter: TrianglePainter(),
),
),
],
),
),
),
],
),
),
],
);
},
),
),
const SizedBox(width: 10),
],
),
],
Expand Down
Loading