Skip to content

Commit

Permalink
LessonCardInfoPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
StarProxima committed May 3, 2023
1 parent 7c78cb1 commit 754772b
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import 'package:cube_system/features/timetable_page/state_holders/lessons/next_l
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/lesson_card_body.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/lesson_card_footer.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/lesson_card_header.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/lesson_card_icons_icon.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/lesson_card_icons.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/info_panel/lesson_card_info_panel_icon.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/info_panel/lesson_card_info_panel_chip.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/info_panel/lesson_card_info_panel.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/lesson_card_indicator.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/lesson_card_time_left.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/next_lesson_time_to_start_progress_bar.dart';
Expand Down Expand Up @@ -125,7 +126,7 @@ class LessonCard extends ConsumerWidget {
const Positioned(
top: 0,
right: 8,
child: LessonCardIcons(),
child: LessonCardInfoPanel(),
),
],
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,47 @@
part of 'package:cube_system/features/timetable_page/features/lesson_card/ui/lesson_card.dart';

class LessonCardIcons extends ConsumerWidget {
const LessonCardIcons({super.key});
class LessonCardInfoPanel extends ConsumerWidget {
const LessonCardInfoPanel({super.key});

static final _random = Random();

@override
Widget build(BuildContext context, WidgetRef ref) {
final color =
ref.watch(appLessonColorByLesson(ref.read(_lessonInLessonCard)));

final isRemotely =
ref.watch(_lessonInLessonCard.select((value) => value.isRemotely));

final isCollision =
ref.watch(_lessonInLessonCard.select((value) => value.isCollision));

final isCancelled =
ref.watch(_lessonInLessonCard.select((value) => value.isCancelled));

final isActiveLessons =
ref.watch(_lessonInLessonCard) == ref.watch(currentLesson);

// final isCollision = _random.nextInt(100) < 25;

// final isRemotely = _random.nextInt(100) < 25;

final isCancelled = _random.nextInt(100) < 0;
// final isCancelled = _random.nextInt(100) < 0;

final presentImportantNote = _random.nextInt(100) < 0;

final numberOfNotes = _random.nextInt(100) < 0 ? _random.nextInt(7) : 0;

return Row(
children: [
if (isCancelled)
const LessonCardIconsIcon.icon(
icon: Icon(Icons.cancel),
isDestructive: true,
),
if (isCollision)
const LessonCardIconsIcon.icon(
icon: Icon(Icons.error),
isDestructive: true,
),
if (isRemotely)
const LessonCardIconsIcon.icon(
const LessonCardInfoPanelIcon(
icon: Icon(Icons.home),
),
if (presentImportantNote)
const LessonCardIconsIcon.icon(
const LessonCardInfoPanelIcon(
icon: Icon(Icons.priority_high_rounded),
),
if (numberOfNotes > 0)
LessonCardIconsIcon.number(
number: numberOfNotes,
LessonCardInfoPanelIcon(
icon: Text('$numberOfNotes'),
),
if (isActiveLessons)
Consumer(
Expand All @@ -64,26 +54,27 @@ class LessonCardIcons extends ConsumerWidget {
final hasHours =
(ref.read(currentLessonTimeToEndProvider)?.hours ?? 0) > 0;

return Container(
margin: const EdgeInsets.only(right: 4),
padding:
const EdgeInsets.symmetric(vertical: 1.5, horizontal: 5),
constraints: BoxConstraints(
minWidth: hasHours ? 66 : 46,
),
decoration: BoxDecoration(
color: color,
borderRadius: const BorderRadius.all(Radius.circular(16)),
),
child: const Center(
child: Padding(
padding: EdgeInsets.only(top: 0.5, left: 0),
child: LessonCardTimeLeft(),
),
),
);
return hasHours
? const LessonCardInfoPanelChip(
minWidth: 66,
text: LessonCardTimeLeft(),
)
: const LessonCardInfoPanelChip(
minWidth: 46,
text: LessonCardTimeLeft(),
);
},
),
if (isCollision)
const LessonCardInfoPanelChip(
text: Text('Коллизия'),
isDestructive: true,
),
if (isCancelled)
const LessonCardInfoPanelChip(
text: Text('Отменено'),
isDestructive: true,
),
],
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
part of 'package:cube_system/features/timetable_page/features/lesson_card/ui/lesson_card.dart';

class LessonCardInfoPanelChip extends ConsumerWidget {
final Widget text;
final bool isDestructive;
final double minWidth;
final Color? color;

const LessonCardInfoPanelChip({
super.key,
required this.text,
this.isDestructive = false,
this.minWidth = 0,
this.color,
});

@override
Widget build(BuildContext context, WidgetRef ref) {
final backgroundColor = isDestructive
? context.colors.destructive
: color ??
ref.watch(appLessonColorByLesson(ref.read(_lessonInLessonCard)));

return Container(
margin: const EdgeInsets.only(right: 4),
padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 6),
constraints: BoxConstraints(minWidth: minWidth),
decoration: BoxDecoration(
color: backgroundColor,
borderRadius: const BorderRadius.all(Radius.circular(16)),
),
child: Center(
child: Padding(
padding: const EdgeInsets.only(top: 0.5, left: 0),
child: DefaultTextStyle(
style: context.textStyles.chipLabel
.copyWith(color: context.colors.white),
child: text,
),
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
part of 'package:cube_system/features/timetable_page/features/lesson_card/ui/lesson_card.dart';

class LessonCardInfoPanelIcon extends ConsumerWidget {
final Widget icon;
final bool isDestructive;
final Color? color;

const LessonCardInfoPanelIcon({
super.key,
required this.icon,
this.isDestructive = false,
this.color,
});

@override
Widget build(BuildContext context, WidgetRef ref) {
final backgroundColor = isDestructive
? context.colors.destructive
: color ??
ref.watch(appLessonColorByLesson(ref.read(_lessonInLessonCard)));

return Container(
margin: const EdgeInsets.only(right: 4),
width: 18,
height: 18,
decoration: BoxDecoration(
color: backgroundColor,
shape: BoxShape.circle,
),
child: Center(
child: DefaultTextStyle(
style: context.textStyles.chipLabel
.copyWith(color: context.colors.white),
child: IconTheme(
data: Theme.of(context).iconTheme.copyWith(
size: 13.5,
color: context.colors.white,
),
child: Padding(
padding: icon is Text
? const EdgeInsets.only(left: 0.4)
: const EdgeInsets.only(bottom: 1, right: 0.2),
child: icon,
),
),
),
),
);
}
}

This file was deleted.

3 changes: 2 additions & 1 deletion lib/features/timetable_page/managers/lesson_convertor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ class LessonConvertor {
isElective: lesson.isElective,
isRemotely: lesson.isRemotely,
isEvent: isEvent,
isCollision: isCollision,
isCancelled: lesson.status == LessonStatus.value_3,
defaultColor: color,
emptyLessonsBefore: emptyLessonsBefore,
isCollision: isCollision,
);

return newLesson;
Expand Down
1 change: 1 addition & 0 deletions lib/models/lesson/lesson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Lesson with _$Lesson {
@HiveField(10) required bool isElective,
@HiveField(11) required bool isEvent,
@HiveField(14, defaultValue: false) required bool isCollision,
@HiveField(15, defaultValue: false) required bool isCancelled,
@HiveField(12) required Color defaultColor,
@HiveField(13) required int emptyLessonsBefore,
}) = _Lesson;
Expand Down
Loading

0 comments on commit 754772b

Please sign in to comment.