Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed overflow of pomodoro screen on landscape #125 #126

Merged
Merged
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
241 changes: 144 additions & 97 deletions lib/screens/task_pomodoro_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:flutter_confetti/flutter_confetti.dart';
import 'package:taskly/enums/timer_types.dart';
import 'package:taskly/models/task.dart';
import 'package:taskly/utils/date_utils.dart';
import 'package:taskly/utils/screen_utils.dart';
import 'package:taskly/widgets/spacing.dart';

import 'package:taskly/constants.dart';
Expand All @@ -24,12 +23,14 @@ class TaskPomodoroScreen extends StatefulWidget {

class _TaskPomodoroScreenState extends State<TaskPomodoroScreen> {
static const int numOfTasksForLongBreak = 4;
// Define breakpoints
static const double narrowScreenWidth = 600;

final CountDownController _controller = CountDownController();
late Duration _duration;

TimerTypes _currentTimerType = TimerTypes.work;
int _workIndex = 1; // the index of the consecutive work timer
int _workIndex = 1;
bool _isStarted = false;

@override
Expand Down Expand Up @@ -78,20 +79,95 @@ class _TaskPomodoroScreenState extends State<TaskPomodoroScreen> {
);
}

Widget _buildTaskCard() {
return Card(
child: ListTile(
title: Text(
widget.task.title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
subtitle: Text(
widget.task.description,
maxLines: 5,
overflow: TextOverflow.ellipsis,
),
trailing: widget.task.hasDeadline
? Text(
MyDateUtils.getFormattedDate(widget.task.deadline!),
style: const TextStyle(color: Colors.red),
)
: null,
),
);
}

Widget _buildTimer(double timerSize) {
if (_isStarted) {
return CircularCountDownTimer(
width: timerSize,
height: timerSize,
duration: _duration.inSeconds,
isReverse: true,
fillColor: Theme.of(context).focusColor,
ringColor: Theme.of(context).highlightColor,
strokeWidth: 16,
isReverseAnimation: true,
textStyle: Theme.of(context).textTheme.displayMedium,
controller: _controller,
onComplete: _onCountdownComplete,
autoStart: true,
);
}

return DurationPicker(
duration: _duration,
baseUnit: BaseUnit.minute,
width: timerSize,
height: timerSize,
lowerBound: Duration(minutes: _currentTimerType.lowerBound),
upperBound: Duration(minutes: _currentTimerType.upperBound),
onChange: (value) => setState(() {
_duration = value;
}),
);
}

Widget _buildActionButton() {
IconData actionIcon = _isStarted
? (_controller.isPaused.value ? Icons.play_arrow_rounded : Icons.pause_rounded)
: Icons.play_arrow_rounded;

return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(48),
),
color: Theme.of(context).primaryColorLight,
child: IconButton(
onPressed: () {
if (!_isStarted) {
setState(() {
_isStarted = true;
});
}
if (_controller.isPaused.value) {
_controller.resume();
} else {
_controller.pause();
}
setState(() {});
},
icon: Icon(actionIcon),
iconSize: 48,
),
);
}

@override
Widget build(BuildContext context) {
final timerSize = ScreenUtils.getPercentOfWidth(context, 0.6);
final helperText = _currentTimerType == TimerTypes.work
? stayFocused(_duration.inMinutes)
: relax(_duration.inMinutes);
IconData actionIcon;
if (_isStarted) {
actionIcon = _controller.isPaused.value
? Icons.play_arrow_rounded
: Icons.pause_rounded;
} else {
actionIcon = Icons.play_arrow_rounded;
}

return Scaffold(
appBar: AppBar(
Expand All @@ -106,94 +182,65 @@ class _TaskPomodoroScreenState extends State<TaskPomodoroScreen> {
),
)
],
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
child: ListTile(
title: Text(
widget.task.title,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
subtitle: Text(
widget.task.description,
maxLines: 5,
overflow: TextOverflow.ellipsis,
body: LayoutBuilder(
builder: (context, constraints) {
final isNarrowScreen = constraints.maxWidth < narrowScreenWidth;
final timerSize = isNarrowScreen
? constraints.maxWidth * 0.6
: constraints.maxHeight * 0.6;

if (isNarrowScreen) {
// Portrait or narrow screen layout
return SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_buildTaskCard(),
const Spacing(large: true),
_buildTimer(timerSize),
const Spacing(),
Text(helperText),
const Spacing(large: true),
_buildActionButton(),
],
),
trailing: widget.task.hasDeadline
? Text(
MyDateUtils.getFormattedDate(widget.task.deadline!),
style: const TextStyle(color: Colors.red),
)
: null,
),
),
),
const Spacing(large: true),
if (_isStarted)
Padding(
padding: const EdgeInsets.all(8.0),
child: CircularCountDownTimer(
width: timerSize,
height: timerSize,
duration: _duration.inSeconds,
isReverse: true,
fillColor: Theme.of(context).focusColor,
ringColor: Theme.of(context).highlightColor,
strokeWidth: 16,
isReverseAnimation: true,
textStyle: Theme.of(context).textTheme.displayMedium,
controller: _controller,
onComplete: _onCountdownComplete,
autoStart: true,
),
),
if (!_isStarted)
Padding(
padding: const EdgeInsets.all(8.0),
child: DurationPicker(
duration: _duration,
baseUnit: BaseUnit.minute,
width: timerSize,
height: timerSize,
lowerBound: Duration(minutes: _currentTimerType.lowerBound),
upperBound: Duration(minutes: _currentTimerType.upperBound),
onChange: (value) => setState(() {
_duration = value;
}),
),
),
const Spacing(),
Text(helperText),
const Spacing(large: true),
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(48),
),
color: Theme.of(context).primaryColorLight,
child: IconButton(
onPressed: () {
if (!_isStarted) {
setState(() {
_isStarted = true;
});
}
if (_controller.isPaused.value) {
_controller.resume();
} else {
_controller.pause();
}
setState(() {});
},
icon: Icon(actionIcon),
iconSize: 48,
),
),
],
);
} else {
// Landscape or wide screen layout
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 2,
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
_buildTaskCard(),
const Spacing(large: true),
Text(helperText),
const Spacing(large: true),
_buildActionButton(),
],
),
),
),
),
Expanded(
flex: 3,
child: Center(
child: _buildTimer(timerSize),
),
),
],
);
}
},
),
);
}
}
}