Skip to content

Commit

Permalink
♻️: global refactor with custom_theme
Browse files Browse the repository at this point in the history
🐛 : fixed datetimepicker bug & fixed overflow in card
  • Loading branch information
julesartd committed Mar 16, 2024
1 parent 644de21 commit 69423fe
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:app_student/login/cubit/login_cubit.dart';
import 'package:app_student/utils/custom_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

import '../../../cubit/login_cubit.dart';

class SubmitButton extends StatelessWidget {
final TextEditingController ineController;
final TextEditingController nameController;
Expand All @@ -30,13 +30,10 @@ class SubmitButton extends StatelessWidget {
child: ElevatedButton(
style: ButtonStyle(
textStyle: MaterialStateProperty.all<TextStyle>(
const TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
CustomTheme.text.toBold,
),
backgroundColor: MaterialStateProperty.all<Color>(
Theme.of(context).focusColor),
CustomTheme.secondaryColor),
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:app_student/utils/custom_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

Expand Down Expand Up @@ -44,10 +45,7 @@ class BirthDateFieldState extends State<BirthDateField> {
children: [
Text(
AppLocalizations.of(context)!.loginBirthDateLabel,
style: TextStyle(
fontSize: 12.0,
color: Colors.grey[600],
),
style: CustomTheme.textSmall,
),
const SizedBox(height: 10.0),
TextFormField(
Expand All @@ -58,11 +56,11 @@ class BirthDateFieldState extends State<BirthDateField> {
contentPadding:
const EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0),
border: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.grey),
borderSide: const BorderSide(color: CustomTheme.primaryColor),
borderRadius: BorderRadius.circular(3.0),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Theme.of(context).focusColor),
borderSide: const BorderSide(color: CustomTheme.secondaryColor),
borderRadius: BorderRadius.circular(3.0),
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:app_student/utils/custom_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

Expand All @@ -9,19 +10,13 @@ class INETextField extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(
left: 25.0,
top: 10.0,
right: 25.0), // Ajout d'un padding à gauche, en haut et à droite
padding: const EdgeInsets.only(left: 25.0, top: 10.0, right: 25.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
AppLocalizations.of(context)!.loginIneLabel,
style: TextStyle(
fontSize: 12.0,
color: Colors.grey[600],
),
style: CustomTheme.textSmall,
),
const SizedBox(height: 10.0),
TextFormField(
Expand All @@ -31,11 +26,11 @@ class INETextField extends StatelessWidget {
contentPadding:
const EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0),
border: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.grey),
borderSide: const BorderSide(color: CustomTheme.primaryColor),
borderRadius: BorderRadius.circular(3.0),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Theme.of(context).focusColor),
borderSide: const BorderSide(color: CustomTheme.secondaryColor),
borderRadius: BorderRadius.circular(3.0),
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:app_student/utils/custom_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

Expand All @@ -15,27 +16,22 @@ class FirstnameTextField extends StatelessWidget {
children: [
Text(
AppLocalizations.of(context)!.loginFirstNameLabel,
style: TextStyle(
fontSize: 12.0,
color: Colors.grey[600],
),
style: CustomTheme.textSmall,
),
const SizedBox(height: 10.0),
TextFormField(
controller: controller,
style: TextStyle(
color: Colors.grey[600],
),
style: CustomTheme.text,
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.loginFirstNameHint,
contentPadding:
const EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0),
border: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.grey),
borderSide: const BorderSide(color: CustomTheme.primaryColor),
borderRadius: BorderRadius.circular(3.0),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Theme.of(context).focusColor),
borderSide: const BorderSide(color: CustomTheme.secondaryColor),
borderRadius: BorderRadius.circular(3.0),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class ClassGroupButton extends StatelessWidget {
textStyle: MaterialStateProperty.all<TextStyle>(
CustomTheme.text.toBold,
),
backgroundColor:
MaterialStateProperty.all<Color>(CustomTheme.secondaryColor),
backgroundColor: MaterialStateProperty.all<Color>(
CustomTheme.secondaryColor),
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class UserClassCard extends StatelessWidget {
leading: SizedBox(
width: 50,
child: ColorFiltered(
colorFilter:
const ColorFilter.mode(CustomTheme.primaryColor, BlendMode.srcIn),
colorFilter: const ColorFilter.mode(
CustomTheme.primaryColor, BlendMode.srcIn),
child: SvgPicture.asset(
'assets/images/user.svg',
width: 30,
Expand All @@ -33,4 +33,4 @@ class UserClassCard extends StatelessWidget {
),
);
}
}
}
13 changes: 6 additions & 7 deletions frontend/app_student/lib/shared_components/app_bar.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:app_student/utils/custom_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

Expand All @@ -17,8 +18,10 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
className = userState.user.className ?? '';
}
return AppBar(
backgroundColor: Theme.of(context).secondaryHeaderColor,
title: title != null ? Text(title!) : const SizedBox.shrink(),
backgroundColor: CustomTheme.primaryColor,
title: title != null
? Text(title!, style: CustomTheme.text.toColorWhite)
: const SizedBox.shrink(),
flexibleSpace: Stack(
children: [
ClipRect(
Expand All @@ -42,11 +45,7 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
Center(
child: Text(
className,
style: const TextStyle(
color: Colors.white,
fontSize: 25.0,
fontWeight: FontWeight.bold,
),
style: CustomTheme.subtitle.toBold.toColorWhite,
),
),
if (widget != null)
Expand Down
5 changes: 3 additions & 2 deletions frontend/app_student/lib/shared_components/header_logo.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:app_student/utils/custom_theme.dart';
import 'package:flutter/cupertino.dart';

class HeaderLogo extends StatelessWidget {
Expand All @@ -6,8 +7,8 @@ class HeaderLogo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: 300.0, // Hauteur du Container
color: const Color(0xFF005067),
height: 300.0,
color: CustomTheme.primaryColor,
child: Center(
child: Padding(
padding: const EdgeInsets.only(top: 50.0),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:app_student/utils/custom_theme.dart';
import 'package:flutter/cupertino.dart';

class HeaderSubtitle extends StatelessWidget {
Expand All @@ -13,11 +14,7 @@ class HeaderSubtitle extends StatelessWidget {
alignment: Alignment.centerLeft,
child: Text(
content,
style: const TextStyle(
fontSize: 18.0,
fontFamily: 'Arial',
fontWeight: FontWeight.bold,
),
style: CustomTheme.subtitle.toBold,
),
),
);
Expand Down
7 changes: 2 additions & 5 deletions frontend/app_student/lib/shared_components/header_title.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:app_student/utils/custom_theme.dart';
import 'package:flutter/cupertino.dart';

class HeaderTitle extends StatelessWidget {
Expand All @@ -13,11 +14,7 @@ class HeaderTitle extends StatelessWidget {
alignment: Alignment.centerLeft,
child: Text(
content,
style: const TextStyle(
fontSize: 34.0,
fontFamily: 'Arial',
fontWeight: FontWeight.bold,
),
style: CustomTheme.title.toBold,
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ class WeekScheduleCubit extends Cubit<WeekScheduleState> {
final allEvents =
weekSchedule.expand((week) => week.daySchedules).toList();

initialDate ??= DateTime.now();
// Only find the closest date if initialDate has not been set
initialDate ??= findClosestDate(allEvents);

final todayIndex = allEvents.indexWhere((daySchedule) =>
daySchedule.date.day == initialDate!.day &&
daySchedule.date.month == initialDate!.month &&
daySchedule.date.year == initialDate!.year);
final todayIndex = findTodayIndex(allEvents);

if (isClosed) {
return;
Expand All @@ -52,6 +50,28 @@ class WeekScheduleCubit extends Cubit<WeekScheduleState> {
}
}

DateTime findClosestDate(List<DayScheduleModel> allEvents) {
// Sort the schedules by date
allEvents.sort((a, b) => a.date.compareTo(b.date));

// Find the schedule with the date closest to today
for (var schedule in allEvents) {
if (schedule.date.isAfter(DateTime.now()) ||
schedule.date.isAtSameMomentAs(DateTime.now())) {
return schedule.date;
}
}

return DateTime.now();
}

int findTodayIndex(List<DayScheduleModel> allEvents) {
return allEvents.indexWhere((daySchedule) =>
daySchedule.date.day == initialDate!.day &&
daySchedule.date.month == initialDate!.month &&
daySchedule.date.year == initialDate!.year);
}

void fetchUserAndSchedule() async {
fetchWeekSchedule();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ class DatePickerButton extends StatelessWidget {
}

Future<DateTime?> selectDate(
BuildContext context, WeekScheduleCubit cubit, DateTime today) async {
BuildContext context, WeekScheduleCubit cubit) async {
return await showDatePicker(
context: context,
initialDate: cubit.state is WeekScheduleLoaded
? (cubit.state as WeekScheduleLoaded)
.allDaySchedules[(cubit.state as WeekScheduleLoaded).todayIndex]
.date
: today,
initialDate: cubit.initialDate ?? DateTime.now(),
firstDate: DateTime(2000),
lastDate: DateTime(2100),
selectableDayPredicate: (date) {
Expand All @@ -49,8 +45,7 @@ class DatePickerButton extends StatelessWidget {
size: 30,
),
onPressed: () async {
final today = DateTime.now();
final date = await selectDate(context, cubit, today);
final date = await selectDate(context, cubit);
if (date != null) {
if (context.mounted) {
await navigateToDate(context, cubit, date); // Await the navigation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class EventCard extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(event.activite, style: CustomTheme.textXl.toBold),
Flexible(
child: Text(event.activite,
style: CustomTheme.textXl.toBold)),
ColorFiltered(
colorFilter:
const ColorFilter.mode(Colors.white, BlendMode.srcIn),
Expand All @@ -54,8 +56,11 @@ class EventCard extends StatelessWidget {
),
],
),
Text('${AppLocalizations.of(context)!.roomLabel} ${event.salle}',
style: CustomTheme.text.toBold),
Flexible(
child: Text(
'${AppLocalizations.of(context)!.roomLabel} ${event.salle}',
style: CustomTheme.text.toBold),
),
],
),
),
Expand Down

0 comments on commit 69423fe

Please sign in to comment.