Skip to content

Commit

Permalink
Merge pull request #13 from FooJiaYin/dev
Browse files Browse the repository at this point in the history
v1.0.3 Update
  • Loading branch information
FooJiaYin authored May 26, 2023
2 parents 45a9386 + b83d575 commit 0c2a0f4
Show file tree
Hide file tree
Showing 19 changed files with 263 additions and 237 deletions.
2 changes: 1 addition & 1 deletion assets/images/home_available.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/images/home_overdue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/payment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion lib/models/machine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Machine with ChangeNotifier {
required this.status,
});

get locationString => "$floor${section ?? ' Floor'}";
get locationString => section!= null ? '$floor$section' : 'Floor $floor';
get name => "${id+1},$locationString";

Machine copyWith({
int? id,
Expand Down
4 changes: 2 additions & 2 deletions lib/services/notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class NotificationService {
static void machineMissed(Machine machine) {
showNotification(
title: "You just missed it!",
body: "${machine.type.name.capitalizeFirst} on ${machine.floor}F is being used by other",
body: "${machine.type.name.capitalizeFirst} ${machine.name} is being used by other",
details: NotificationService.machineAvailableNotificationDetails,
);
}
Expand All @@ -139,7 +139,7 @@ class NotificationService {
static void laundryDone(Machine machine, Dormitory dorm) {
showNotification(
title: "Laundry is done!",
body: "on ${machine.locationString}, ${dorm.name}",
body: "${machine.type.name.capitalizeFirst} ${machine.name}, ${dorm.name}",
payload: "current_machine",
details: NotificationService.laundryDoneNotificationDetails,
);
Expand Down
9 changes: 7 additions & 2 deletions lib/theme/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CustomTheme with ChangeNotifier {
scaffoldBackgroundColor: ThemeColors.backgroundColor,
backgroundColor: ThemeColors.backgroundColor,
shadowColor: ThemeColors.grey,
disabledColor: Colors.grey,
disabledColor: ThemeColors.lightGrey,
textTheme: ThemeFont.textTheme,
buttonTheme: ButtonThemeData(
// 4
Expand Down Expand Up @@ -87,7 +87,12 @@ class CustomTheme with ChangeNotifier {
chipTheme: ChipThemeData(
side: BorderSide.none,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(Dimensions.buttonRadius)),
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 6),
padding: const EdgeInsets.symmetric(horizontal: 4),
),
checkboxTheme: CheckboxThemeData(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
side: const BorderSide(color: ThemeColors.grey, width: 1.5),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
),
);

Expand Down
93 changes: 45 additions & 48 deletions lib/views/components/machine_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import '../../services/fake_data.dart';
import '../../theme/theme.dart';
import '../../utils/string.dart';
import 'machine_status_card.dart';
import 'select_chip.dart';
import 'neumorphic_container.dart';
import 'waiting_switch.dart';

class MachineList extends StatefulWidget {
Expand Down Expand Up @@ -47,7 +47,7 @@ class _MachineListState extends State<MachineList> {
@override
Widget build(BuildContext context) {
state = GlobalState.of(context);
floorFilter(machine) => state?.viewIndex == 0 ? machine.floor == state?.floor : machine.status.code == StatusCode.available;
floorFilter(machine) => state?.viewIndex == 0 ? state!.subscribedFloors.contains(machine.floor) : machine.status.code == StatusCode.available;

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -58,18 +58,18 @@ class _MachineListState extends State<MachineList> {
const SizedBox(width: 8),
Text(type.name.capitalizeEach, style: ThemeFont.header()),
const SizedBox(width: 8),
if (state?.status != Status.using) _waitingButton(),
state?.status != Status.using ? _waitingButton() : const SizedBox(height: 48),
],
),
if (state?.status != Status.using) _floorChipsPanel(),
_floorChipsPanel(),
const SizedBox(height: 8),
ProxyProvider<GlobalState, List<Machine>>(
update: (_, state, __) => state.floor != null ? machines.where(floorFilter).toList() : [],
update: (_, state, __) => state.floor != null ? machines.where(floorFilter).toList().sortByNearestFloor(state.floor ?? 0) : [],
child: Builder(
builder: (context) => GridView.count(
clipBehavior: Clip.none,
crossAxisCount: 3,
crossAxisSpacing: 24,
crossAxisSpacing: 20,
mainAxisSpacing: 24,
childAspectRatio: 0.65,
primary: true,
Expand Down Expand Up @@ -108,65 +108,62 @@ class _MachineListState extends State<MachineList> {
),
);

Widget _floorChipsPanel() => InkWell(
onTap: () => setState(() {
selectFloors = false;
}),
child: AnimatedContainer(
duration: const Duration(milliseconds: 100),
height: selectFloors ? null : 0,
child: Wrap(
clipBehavior: Clip.hardEdge,
spacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
/// Select All or Clear
state!.subscribedFloors.length >= floors.length ? _clearAllButton : _selectAllButton,
Widget _floorChipsPanel() => AnimatedContainer(
duration: const Duration(milliseconds: 100),
height: selectFloors ? null : 0,
padding: const EdgeInsets.only(bottom: 8),
child: Wrap(
clipBehavior: Clip.hardEdge,
spacing: 8,
runSpacing: 8,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
/// Select All or Clear
state!.subscribedFloors.length >= floors.length ? _clearAllButton : _selectAllButton,

/// Floor chips
...floors.map(floorChip).toList(),
// Icon(Icons.keyboard_arrow_up_rounded)
// Text("Close", style: ThemeFont.small)
],
),
/// Floor chips
...floors.map(floorChip).toList(),
],
),
);

Widget get _selectAllButton => SelectChip(
label: " All",
icon: "bell_outlined",
Widget get _selectAllButton => NeumorphicChip(
"All",
onSelected: (_) => setState(() {
GlobalState.set(context, subscribedFloors: floors.toSet(), status: Status.waiting);
GlobalState.set(context, subscribedFloors: floors.toSet());
}),
);

Widget get _clearAllButton => SelectChip(
label: " Clear",
Widget get _clearAllButton => NeumorphicChip(
"Reset",
onSelected: (_) => setState(() {
GlobalState.set(context, subscribedFloors: {state!.floor!}, status: Status.idle);
GlobalState.set(context, subscribedFloors: {state!.floor!});
}),
);

SelectChip floorChip(int floor) => SelectChip(
label: " ${floor}F",
icon: "bell_outlined",
isSelected: state?.status == Status.waiting && subscribedFloors.contains(floor),
Widget floorChip(int floor) => NeumorphicChip(
"${floor}F",
isSelected: subscribedFloors.contains(floor),
onSelected: (isSelected) => setState(() {
if (isSelected) {
if (state?.status == Status.waiting) {
subscribedFloors.add(floor);
} else {
state?.subscribedFloors = {floor};
}
GlobalState.set(context, status: Status.waiting);
subscribedFloors.add(floor);
} else {
subscribedFloors.remove(floor);
GlobalState.set(
context,
status: subscribedFloors.isEmpty ? Status.idle : null,
subscribedFloors: subscribedFloors.isEmpty ? {state!.floor!} : subscribedFloors,
);
if (subscribedFloors.isEmpty) subscribedFloors.add(state!.floor!);
}
GlobalState.set(context, currentMachine: null);
FakeData.updateCurrentMachine(GlobalState.instance);
}),
);
}

Widget NeumorphicChip(String label, {bool isSelected = false, double? fontSize = 12, EdgeInsets padding = const EdgeInsets.symmetric(vertical: 6, horizontal: 12), onSelected}) => NeumorphicContainer(
width: null,
borderRadius: 40.0,
padding: padding,
shadows: ThemeDecoration.circleShadow,
backgroundColor: isSelected ? ThemeColors.backgroundColor : ThemeColors.lightGrey,
gradient: isSelected ? ThemeColors.blueRingGradient : null,
onTap: () => onSelected(!isSelected),
child: Text(label, style: ThemeFont.style(color: isSelected ? Colors.white : null, fontSize: fontSize)),
);
45 changes: 24 additions & 21 deletions lib/views/components/machine_status_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,39 @@ class MachineStatusCard extends StatelessWidget {

final Machine data;

void openMachinePage(context) {
if (GlobalState.of(context, listen: false).currentMachine?.status.code != StatusCode.in_use) {
GlobalState.set(context, status: Status.pay);
}
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (context) => MachinePage(data),
),
);
}

@override
Widget build(BuildContext context) {
return NeumorphicContainer(
padding: const EdgeInsets.all(16),
onTap: () => GlobalState.of(context, listen: false).anonymous
? showDialog(context: context, builder: (context) => const SelectDormDialog())
: Navigator.push(
context,
MaterialPageRoute<void>(
builder: (context) => MachinePage(data),
),
),
: openMachinePage(context),
child: Column(
children: [
Text(
data.locationString,
style: ThemeFont.small,
),
Text(data.name, style: ThemeFont.small),
const SizedBox(height: 4),
if (data.status.code == StatusCode.in_use)
Expanded(
child: ProgressRing(
value: data.status.durationPassed.inMinutes / data.status.durationEstimated.inMinutes,
strokeWidth: 5.5,
strokeGradient: ThemeColors.blueRingGradient,
child: Text("${data.status.minutesLeft}m"),
),
)
else
SvgPicture.asset('assets/images/home_${data.status.code.name}.svg'),
Expanded(
child: data.status.code == StatusCode.in_use
? ProgressRing(
value: data.status.durationPassed.inMinutes / data.status.durationEstimated.inMinutes,
strokeWidth: 5.5,
strokeGradient: ThemeColors.blueRingGradient,
child: Text("${data.status.minutesLeft}m"),
)
: SvgPicture.asset('assets/images/home_${data.status.code.name}.svg'),
),
const SizedBox(height: 6),
Text(
data.status.code.name.splitUnderScore.capitalizeEach,
Expand Down
14 changes: 13 additions & 1 deletion lib/views/components/neumorphic_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class NeumorphicButton extends StatelessWidget {
Key? key,
required this.text,
this.textColor,
this.disabled = false,
this.gradient,
this.width = double.infinity,
this.onPressed,
Expand All @@ -17,6 +18,7 @@ class NeumorphicButton extends StatelessWidget {
final Color? textColor;
final Gradient? gradient;
final double? width;
final bool disabled;
final dynamic onPressed;

@override
Expand All @@ -28,15 +30,25 @@ class NeumorphicButton extends StatelessWidget {
boxShadow: ThemeDecoration.neumorphicShadow,
),
child: Button(
disabled: disabled,
backgroundColor: gradient == null ? ThemeColors.backgroundColor : Colors.transparent,
gradient: gradient,
text: text,
textStyle: TextStyle(
color: textColor ?? (gradient != null ? Colors.white : ThemeColors.darkGrey),
color: textColor ?? (disabled ? ThemeColors.grey : gradient != null ? Colors.white : ThemeColors.darkGrey),
),
width: width,
onPressed: onPressed,
),
);
}

static confirm({bool disabled = false, onPressed}) {
return NeumorphicButton(
text: "Confirm",
disabled: disabled,
gradient: ThemeColors.blueRingGradient,
onPressed: onPressed,
);
}
}
Loading

0 comments on commit 0c2a0f4

Please sign in to comment.