6 Commits

Author SHA1 Message Date
3940184975 Fix Displaying Bug 2024-05-14 20:58:22 +02:00
eee1d12851 Fix Version Name for new Release 2024-03-15 23:05:33 +01:00
e11a73d37e Fixed Android Label 2024-03-15 23:02:13 +01:00
ead31e12c0 Fixed Remaining Migration Errors 2024-03-15 22:47:43 +01:00
421d19f91f Fixed Remaining Problems 2024-03-15 21:09:16 +01:00
3085a295e5 Fixed Simple Problem, that occured after migrating to new version.
Still WIP need to fix more Problems
2024-03-15 07:05:10 +01:00
43 changed files with 450 additions and 362 deletions

View File

@ -22,6 +22,12 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
namespace "com.fahrecker.time_progress_calculator"
compileSdk flutter.compileSdkVersion

View File

@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fahrecker.time_progress_calculator">
<application
android:label="time_progress_tracker"
android:label="Time Progress Tracker"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity

View File

@ -49,8 +49,9 @@ class DeleteTimeProgressAction {
}
void loadTimeProgressListIfUnloaded(Store<AppState> store) {
if (!store.state.hasProgressesLoaded)
if (!store.state.hasProgressesLoaded) {
store.dispatch(LoadTimeProgressListAction());
}
}
void loadSettingsIfUnloaded(Store<AppState> store) {

View File

@ -11,10 +11,10 @@ class TimeProgressTrackerApp extends StatelessWidget {
final Store<AppState> store;
TimeProgressTrackerApp({
Key key,
this.store,
}) : super(key: key);
const TimeProgressTrackerApp({
super.key,
required this.store,
});
@override
Widget build(BuildContext context) {
@ -23,19 +23,22 @@ class TimeProgressTrackerApp extends StatelessWidget {
child: MaterialApp(
title: name,
theme: ThemeData(
primarySwatch: Colors.indigo,
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.indigo,
accentColor: Colors.indigoAccent,
backgroundColor: Colors.white
),
brightness: Brightness.light,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
initialRoute: HomeScreen.routeName,
routes: {
HomeScreen.routeName: (BuildContext context) =>
HomeScreen(),
HomeScreen.routeName: (BuildContext context) => const HomeScreen(),
ProgressDetailScreen.routeName: (BuildContext context) =>
ProgressDetailScreen(),
const ProgressDetailScreen(),
ProgressCreationScreen.routeName: (BuildContext context) =>
ProgressCreationScreen(),
const ProgressCreationScreen(),
},
),
);

View File

@ -3,7 +3,7 @@ import 'dart:ui';
import 'package:time_progress_tracker/models/time_progress.dart';
TimeProgress selectProgressById(List<TimeProgress> tpList, String id) =>
tpList.firstWhere((tp) => tp.id == id, orElse: null);
tpList.firstWhere((tp) => tp.id == id, orElse: () => TimeProgress.initialDefault());
List<TimeProgress> selectActiveProgresses(List<TimeProgress> tpList) =>
tpList.where((tp) => tp.hasStarted() && !tp.hasEnded()).toList();

View File

@ -17,12 +17,12 @@ List<Middleware<AppState>> createStoreMiddleware(
final loadSettings = _createLoadAppSettings(settingsRepo);
return [
TypedMiddleware<AppState, LoadTimeProgressListAction>(loadTimeProgressList),
TypedMiddleware<AppState, AddTimeProgressAction>(saveTimeProgressList),
TypedMiddleware<AppState, UpdateTimeProgressAction>(saveTimeProgressList),
TypedMiddleware<AppState, DeleteTimeProgressAction>(saveTimeProgressList),
TypedMiddleware<AppState, LoadSettingsAction>(loadSettings),
TypedMiddleware<AppState, UpdateAppSettingsActions>(saveSettings)
TypedMiddleware<AppState, LoadTimeProgressListAction>(loadTimeProgressList).call,
TypedMiddleware<AppState, AddTimeProgressAction>(saveTimeProgressList).call,
TypedMiddleware<AppState, UpdateTimeProgressAction>(saveTimeProgressList).call,
TypedMiddleware<AppState, DeleteTimeProgressAction>(saveTimeProgressList).call,
TypedMiddleware<AppState, LoadSettingsAction>(loadSettings).call,
TypedMiddleware<AppState, UpdateAppSettingsActions>(saveSettings).call
];
}
@ -45,9 +45,6 @@ Middleware<AppState> _createLoadTimeProgressList(
repository.loadTimeProgressList().then((timeProgresses) {
List<TimeProgress> timeProgressList =
timeProgresses.map<TimeProgress>(TimeProgress.fromEntity).toList();
if (timeProgressList == null) {
timeProgressList = [];
}
store.dispatch(TimeProgressListLoadedAction(
timeProgressList,
));

View File

@ -1,5 +1,5 @@
class TimeProgressInvalidNameException implements Exception {
final invalidName;
final String invalidName;
TimeProgressInvalidNameException(this.invalidName);
@ -7,8 +7,8 @@ class TimeProgressInvalidNameException implements Exception {
}
class TimeProgressStartTimeIsNotBeforeEndTimeException implements Exception {
final startTime;
final endTime;
final DateTime startTime;
final DateTime endTime;
TimeProgressStartTimeIsNotBeforeEndTimeException(
this.startTime, this.endTime);

View File

@ -7,22 +7,22 @@ class AppSettings {
final Color leftColor;
final Duration duration;
AppSettings({
this.doneColor,
this.leftColor,
this.duration,
const AppSettings({
required this.doneColor,
required this.leftColor,
required this.duration,
});
factory AppSettings.defaults() => AppSettings(
factory AppSettings.defaults() => const AppSettings(
doneColor: Colors.green,
leftColor: Colors.red,
duration: Duration(days: 365),
);
AppSettings copyWith({
Color doneColor,
Color leftColor,
Duration duration,
Color? doneColor,
Color? leftColor,
Duration? duration,
}) =>
AppSettings(
doneColor: doneColor ?? this.doneColor,

View File

@ -8,22 +8,24 @@ class AppState {
final List<TimeProgress> timeProgressList;
final AppSettings appSettings;
AppState(
const AppState(
{this.hasProgressesLoaded = false,
this.hasSettingsLoaded = false,
this.timeProgressList = const [],
this.appSettings});
required this.appSettings});
factory AppState.initial() =>
AppState(hasProgressesLoaded: false, appSettings: AppSettings.defaults());
AppState copyWith({
bool hasLoaded,
List<TimeProgress> timeProgressList,
bool? hasLoaded,
List<TimeProgress>? timeProgressList,
AppSettings? appSettings,
}) {
return AppState(
hasProgressesLoaded: hasLoaded ?? this.hasProgressesLoaded,
hasProgressesLoaded: hasLoaded ?? hasProgressesLoaded,
timeProgressList: timeProgressList ?? this.timeProgressList,
appSettings: appSettings ?? this.appSettings,
);
}

View File

@ -10,7 +10,7 @@ class TimeProgress {
final DateTime startTime;
final DateTime endTime;
TimeProgress(this.name, this.startTime, this.endTime, {String id})
TimeProgress(this.name, this.startTime, this.endTime, {String? id})
: id = id ?? Uuid().generateV4();
factory TimeProgress.initialDefault() {
@ -23,7 +23,7 @@ class TimeProgress {
TimeProgress("", DateTime.now(), DateTime.now().add(duration));
TimeProgress copyWith(
{String id, String name, DateTime startTime, DateTime endTime}) =>
{String? id, String? name, DateTime? startTime, DateTime? endTime}) =>
TimeProgress(
name ?? this.name,
startTime ?? this.startTime,
@ -38,7 +38,7 @@ class TimeProgress {
int allDays() => endTime.difference(startTime).inDays;
double percentDone() {
double percent = this.daysBehind() / (this.allDays() / 100) / 100;
double percent = daysBehind() / (allDays() / 100) / 100;
if (percent < 0) percent = 0;
if (percent > 1) percent = 1;
return percent;
@ -48,7 +48,7 @@ class TimeProgress {
DateTime.now().millisecondsSinceEpoch > startTime.millisecondsSinceEpoch;
int daysTillStart() {
if (hasStarted()) throw new TimeProgressHasStartedException();
if (hasStarted()) throw TimeProgressHasStartedException();
return startTime.difference(DateTime.now()).inDays;
}
@ -56,7 +56,7 @@ class TimeProgress {
DateTime.now().millisecondsSinceEpoch > endTime.millisecondsSinceEpoch;
int daysSinceEnd() {
if (!hasEnded()) throw new TimeProgressHasNotEndedException();
if (!hasEnded()) throw TimeProgressHasNotEndedException();
return DateTime.now().difference(endTime).inDays;
}
@ -79,24 +79,26 @@ class TimeProgress {
"TimeProgress{id: $id, name: $name, startTime: $startTime, endTime: $endTime}";
TimeProgressEntity toEntity() {
if (!TimeProgress.isNameValid(name))
throw new TimeProgressInvalidNameException(name);
if (!TimeProgress.areTimesValid(startTime, endTime))
throw new TimeProgressStartTimeIsNotBeforeEndTimeException(
if (!TimeProgress.isNameValid(name)) {
throw TimeProgressInvalidNameException(name);
}
if (!TimeProgress.areTimesValid(startTime, endTime)) {
throw TimeProgressStartTimeIsNotBeforeEndTimeException(
startTime, endTime);
}
return TimeProgressEntity(id, name, startTime, endTime);
}
static TimeProgress fromEntity(TimeProgressEntity entity) =>
TimeProgress(entity.name, entity.startTime, entity.endTime,
id: entity.id ?? Uuid().generateV4());
id: entity.id);
static bool isValid(TimeProgress tp) =>
TimeProgress.isNameValid(tp.name) &&
TimeProgress.areTimesValid(tp.startTime, tp.endTime);
static bool isNameValid(String name) =>
name != null && name != "" && name.length > 2 && name.length < 21;
name != "" && name.length > 2 && name.length < 21;
static bool areTimesValid(DateTime startTime, DateTime endTime) =>
startTime.isBefore(endTime);

View File

@ -11,15 +11,16 @@ class AppSettingsRepository {
AppSettingsRepository(this.prefs, {this.codec = json});
Future<AppSettingsEntity> loadAppSettings() {
final String jsonString = this.prefs.getString(_key);
if (jsonString == null)
final String? jsonString = prefs.getString(_key);
if (jsonString == null) {
return Future<AppSettingsEntity>.value(AppSettingsEntity.defaults());
}
return Future<AppSettingsEntity>.value(
AppSettingsEntity.fromJson(codec.decode(jsonString)));
}
Future<bool> saveAppSettings(AppSettingsEntity appSettings) =>
this.prefs.setString(_key, codec.encode(appSettings));
prefs.setString(_key, codec.encode(appSettings));
}
class AppSettingsEntity {
@ -52,8 +53,8 @@ class AppSettingsEntity {
static AppSettingsEntity fromJson(Map<String, Object> json) =>
AppSettingsEntity(
json[_doneKey],
json[_leftKey],
json[_durationDaysKey],
json[_doneKey] as int,
json[_leftKey] as int,
json[_durationDaysKey] as int,
);
}

View File

@ -29,7 +29,7 @@ class TimeProgressEntity {
};
}
static TimeProgressEntity fromJson(Map<String, Object> json) {
static TimeProgressEntity fromJson(dynamic json) {
final String id = json["id"] as String;
final String name = json["name"] as String;
final DateTime startTime =

View File

@ -10,13 +10,12 @@ class TimeProgressRepository {
TimeProgressRepository(this.prefs, {this.codec = json});
Future<List<TimeProgressEntity>> loadTimeProgressList() {
final String jsonString = this.prefs.getString(_key);
final String? jsonString = prefs.getString(_key);
if (jsonString == null) {
return Future<List<TimeProgressEntity>>.value([]);
}
return Future<List<TimeProgressEntity>>.value(codec
.decode(jsonString)["timers"]
.cast<Map<String, Object>>()
.map<TimeProgressEntity>(TimeProgressEntity.fromJson)
.toList(growable: false));
}
@ -24,6 +23,6 @@ class TimeProgressRepository {
Future<bool> saveTimeProgressList(List<TimeProgressEntity> timeProgressList) {
final String jsonString = codec.encode(
{"timers": timeProgressList.map((timer) => timer.toJson()).toList()});
return this.prefs.setString(_key, jsonString);
return prefs.setString(_key, jsonString);
}
}

View File

@ -17,9 +17,9 @@ AppState appStateReducer(AppState state, dynamic action) {
}
final appSettingsReducers = combineReducers<AppSettings>([
TypedReducer<AppSettings, AppSettingsLoadedActions>(_loadAppSettings),
TypedReducer<AppSettings, UpdateAppSettingsActions>(_updateAppSettings),
TypedReducer<AppSettings, AppSettingsNotLoadedAction>(_setDefaultSettings)
TypedReducer<AppSettings, AppSettingsLoadedActions>(_loadAppSettings).call,
TypedReducer<AppSettings, UpdateAppSettingsActions>(_updateAppSettings).call,
TypedReducer<AppSettings, AppSettingsNotLoadedAction>(_setDefaultSettings).call
]);
AppSettings _loadAppSettings(

View File

@ -2,8 +2,8 @@ import 'package:redux/redux.dart';
import 'package:time_progress_tracker/actions/actions.dart';
final hasProgressesLoadedReducer = combineReducers<bool>([
TypedReducer<bool, TimeProgressListLoadedAction>(_setProgressesLoaded),
TypedReducer<bool, TimeProgressListNotLoadedAction>(_setProgressesUnloaded)
TypedReducer<bool, TimeProgressListLoadedAction>(_setProgressesLoaded).call,
TypedReducer<bool, TimeProgressListNotLoadedAction>(_setProgressesUnloaded).call
]);
bool _setProgressesLoaded(bool hasLoaded, TimeProgressListLoadedAction action) {
@ -15,8 +15,8 @@ bool _setProgressesUnloaded(bool hasLoaded, TimeProgressListNotLoadedAction acti
}
final hasSettingsLoadedReducer = combineReducers<bool>([
TypedReducer<bool, AppSettingsLoadedActions>(_setSettingsLoaded),
TypedReducer<bool, AppSettingsNotLoadedAction>(_setSettingsUnloaded)
TypedReducer<bool, AppSettingsLoadedActions>(_setSettingsLoaded).call,
TypedReducer<bool, AppSettingsNotLoadedAction>(_setSettingsUnloaded).call
]);
bool _setSettingsLoaded(bool hasLoaded, AppSettingsLoadedActions action) {

View File

@ -4,13 +4,13 @@ import 'package:time_progress_tracker/models/time_progress.dart';
final timeProgressListReducer = combineReducers<List<TimeProgress>>([
TypedReducer<List<TimeProgress>, TimeProgressListLoadedAction>(
_setLoadedTimeProgressList),
_setLoadedTimeProgressList).call,
TypedReducer<List<TimeProgress>, TimeProgressListNotLoadedAction>(
_setEmptyTimeProgressList),
TypedReducer<List<TimeProgress>, AddTimeProgressAction>(_addTimeProgress),
_setEmptyTimeProgressList).call,
TypedReducer<List<TimeProgress>, AddTimeProgressAction>(_addTimeProgress).call,
TypedReducer<List<TimeProgress>, UpdateTimeProgressAction>(
_updateTimeProgress),
TypedReducer<List<TimeProgress>, DeleteTimeProgressAction>(_deleteTimeProgress),
_updateTimeProgress).call,
TypedReducer<List<TimeProgress>, DeleteTimeProgressAction>(_deleteTimeProgress).call,
]);
List<TimeProgress> _setLoadedTimeProgressList(

View File

@ -9,6 +9,8 @@ class HomeScreen extends StatefulWidget {
static const routeName = "/home";
static const title = "Time Progress Tracker";
const HomeScreen({super.key});
@override
State<StatefulWidget> createState() {
return _HomeScreenState();
@ -18,9 +20,9 @@ class HomeScreen extends StatefulWidget {
class _HomeScreenState extends State<HomeScreen> {
int _currentIndex = 0;
final List<Widget> _children = [
HomeActiveProgressesTab(),
HomeInactiveProgressesTab(),
HomeSettingsTab(),
const HomeActiveProgressesTab(),
const HomeInactiveProgressesTab(),
const HomeSettingsTab(),
];
void onBottomTabTapped(int index) {
@ -31,13 +33,16 @@ class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
final ThemeData appTheme = Theme.of(context);
return Scaffold(
appBar: AppBar(
title: Text(HomeScreen.title),
title: const Text(HomeScreen.title),
backgroundColor: appTheme.colorScheme.primary,
),
body: _children[_currentIndex],
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
floatingActionButton: _currentIndex != 2 ? CreateProgressButton() : null,
floatingActionButton: _currentIndex != 2 ? const CreateProgressButton() : null,
bottomNavigationBar: HomeBottomNavBar(
currentIndex: _currentIndex,
onTap: onBottomTabTapped,

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';
import 'package:time_progress_tracker/actions/actions.dart';
@ -13,6 +12,8 @@ class ProgressCreationScreen extends StatefulWidget {
static const routeName = "/create-progress";
static const title = "Create Time Progress";
const ProgressCreationScreen({super.key});
@override
State<StatefulWidget> createState() {
return _ProgressCreationScreenState();
@ -20,15 +21,16 @@ class ProgressCreationScreen extends StatefulWidget {
}
class _ProgressCreationScreenState extends State<ProgressCreationScreen> {
TimeProgress timeProgressToCreate;
TimeProgress? timeProgressToCreate;
bool _isProgressValid = false;
void initTimeProgress(TimeProgress timeProgress) {
if (timeProgressToCreate == null)
if (timeProgressToCreate == null) {
setState(() {
timeProgressToCreate = timeProgress;
});
}
}
void onTimeProgressChanged(
TimeProgress newTimeProgress, bool isNewProgressValid) {
@ -40,19 +42,25 @@ class _ProgressCreationScreenState extends State<ProgressCreationScreen> {
@override
Widget build(BuildContext context) {
final ThemeData appTheme = Theme.of(context);
return Scaffold(
appBar: AppBar(
title: Text(ProgressCreationScreen.title),
title: const Text(ProgressCreationScreen.title),
backgroundColor: appTheme.colorScheme.primary,
),
body: Container(
padding: EdgeInsets.all(12),
padding: const EdgeInsets.all(12),
child: StoreConnector<AppState, _ViewModel>(
onInit: loadSettingsIfUnloaded,
converter: (store) => _ViewModel.create(store),
builder: (context, _ViewModel viewModel) {
WidgetsBinding.instance.addPostFrameCallback((_) {
initTimeProgress(viewModel.defaultDurationProgress);
});
return ProgressEditorWidget(
timeProgress: timeProgressToCreate,
timeProgress:
timeProgressToCreate ?? viewModel.defaultDurationProgress,
onTimeProgressChanged: onTimeProgressChanged,
);
}),
@ -66,23 +74,24 @@ class _ProgressCreationScreenState extends State<ProgressCreationScreen> {
converter: (store) => _ViewModel.create(store),
builder: (context, _ViewModel vm) => FloatingActionButton(
heroTag: "createTimeProgressBTN",
child: Icon(Icons.save),
onPressed: _isProgressValid
? () {
vm.onAddTimeProgress(timeProgressToCreate);
vm.onAddTimeProgress(
timeProgressToCreate ?? vm.defaultDurationProgress);
Navigator.pop(context);
}
: null,
child: const Icon(Icons.save),
),
),
),
Expanded(
child: FloatingActionButton(
heroTag: "cancelTimeProgressCreationBTN",
child: Icon(Icons.cancel),
onPressed: () {
Navigator.pop(context);
},
child: const Icon(Icons.cancel),
),
)
],
@ -96,21 +105,21 @@ class _ViewModel {
final void Function(TimeProgress) onAddTimeProgress;
_ViewModel({
@required this.defaultDurationProgress,
@required this.onAddTimeProgress,
required this.defaultDurationProgress,
required this.onAddTimeProgress,
});
factory _ViewModel.create(Store<AppState> store) {
AppSettings settings = appSettingsSelector(store.state);
_onAddTimeProgress(TimeProgress tp) {
onAddTimeProgress(TimeProgress tp) {
if (TimeProgress.isValid(tp)) store.dispatch(AddTimeProgressAction(tp));
}
return _ViewModel(
defaultDurationProgress:
TimeProgress.defaultFromDuration(settings.duration),
onAddTimeProgress: _onAddTimeProgress,
onAddTimeProgress: onAddTimeProgress,
);
}
}

View File

@ -17,6 +17,8 @@ class ProgressDetailScreen extends StatefulWidget {
static const routeName = "/progress";
static const title = "Progress View";
const ProgressDetailScreen({super.key});
@override
State<StatefulWidget> createState() {
return _ProgressDetailScreenState();
@ -25,7 +27,7 @@ class ProgressDetailScreen extends StatefulWidget {
class _ProgressDetailScreenState extends State<ProgressDetailScreen> {
bool _editMode = false, _isEditedProgressValid = false;
TimeProgress _editedProgress, _originalProgress;
TimeProgress? _editedProgress, _originalProgress;
void _initEditedProgress(TimeProgress tp) {
if (_editedProgress == null) {
@ -57,31 +59,35 @@ class _ProgressDetailScreenState extends State<ProgressDetailScreen> {
List<Widget> _renderColumnChildren(
SettingsViewModel settingsVm, TimeProgressViewModel tpVm) {
List<Widget> columnChildren = [
Expanded(
List<Widget> columnChildren = [];
if (!_editMode) {
columnChildren.add(Expanded(
child: ProgressViewWidget(
timeProgress: _editMode ? _editedProgress : tpVm.tp,
timeProgress: _editMode ? _editedProgress ?? tpVm.tp : tpVm.tp,
doneColor: settingsVm.appSettings.doneColor,
leftColor: settingsVm.appSettings.leftColor,
))
];
if (_editMode)
)));
} else {
columnChildren.add(Expanded(
child: ProgressEditorWidget(
timeProgress: _editedProgress,
timeProgress: _editedProgress ?? tpVm.tp,
onTimeProgressChanged: _onEditedProgressChanged,
)));
}
return columnChildren;
}
@override
Widget build(BuildContext context) {
final ProgressDetailScreenArguments args =
ModalRoute.of(context).settings.arguments;
final ThemeData appTheme = Theme.of(context);
final ProgressDetailScreenArguments args = ModalRoute.of(context)
?.settings
.arguments as ProgressDetailScreenArguments;
return Scaffold(
appBar: AppBar(
title: Text(ProgressDetailScreen.title),
title: const Text(ProgressDetailScreen.title),
backgroundColor: appTheme.colorScheme.primary,
),
body: SettingsStoreConnector(
loadedBuilder: (context, settingsVm) {
@ -90,10 +96,11 @@ class _ProgressDetailScreenState extends State<ProgressDetailScreen> {
loadedBuilder: (context, tpVm) {
_initEditedProgress(tpVm.tp);
return Container(
margin: EdgeInsets.all(8),
margin: const EdgeInsets.all(8),
child: Column(
children: _renderColumnChildren(settingsVm, tpVm),
));
),
);
},
);
},
@ -102,12 +109,12 @@ class _ProgressDetailScreenState extends State<ProgressDetailScreen> {
floatingActionButton: TimeProgressStoreConnector(
timeProgressId: args.id,
loadedBuilder: (context, tpVm) {
void _saveEditedProgress() {
tpVm.updateTimeProgress(_editedProgress);
void saveEditedProgress() {
tpVm.updateTimeProgress(_editedProgress ?? tpVm.tp);
_switchEditMode(false);
}
void _deleteTimeProgress() {
void deleteTimeProgress() {
tpVm.deleteTimeProgress();
Navigator.popUntil(
context, ModalRoute.withName(HomeScreen.routeName));
@ -116,12 +123,12 @@ class _ProgressDetailScreenState extends State<ProgressDetailScreen> {
return DetailScreenFloatingActionButtons(
editMode: _editMode,
originalProgress: tpVm.tp,
editedProgress: _editedProgress,
editedProgress: _editedProgress ?? tpVm.tp,
isEditedProgressValid: _isEditedProgressValid,
onEditProgress: () => _switchEditMode(true),
onSaveEditedProgress: _saveEditedProgress,
onSaveEditedProgress: saveEditedProgress,
onCancelEditProgress: _cancelEditMode,
onDeleteProgress: _deleteTimeProgress);
onDeleteProgress: deleteTimeProgress);
},
),
);

View File

@ -45,10 +45,11 @@ List<TimeProgress> pastTimeProgressesSelector(AppState state) =>
DateTime.now().millisecondsSinceEpoch)
.toList();
TimeProgress timeProgressByIdSelector(AppState state, String id) {
if (state.timeProgressList.length < 1) return null;
return state.timeProgressList
.firstWhere((timeProgress) => timeProgress.id == id, orElse: () => null);
TimeProgress? timeProgressByIdSelector(AppState state, String id) {
if (state.timeProgressList.isEmpty) return null;
return state.timeProgressList.firstWhere(
(timeProgress) => timeProgress.id == id,
orElse: () => TimeProgress.initialDefault());
}
AppSettings appSettingsSelector(AppState state) {

View File

@ -5,12 +5,12 @@ class AppYesNoDialog extends StatelessWidget {
final String contentText;
final void Function() onYesPressed;
AppYesNoDialog({
Key key,
@required this.titleText,
@required this.contentText,
@required this.onYesPressed,
}) : super(key: key);
const AppYesNoDialog({
super.key,
required this.titleText,
required this.contentText,
required this.onYesPressed,
});
@override
Widget build(BuildContext context) {
@ -18,15 +18,15 @@ class AppYesNoDialog extends StatelessWidget {
title: Text(titleText),
content: Text(contentText),
actions: <Widget>[
FlatButton(
child: Text("Yes"),
TextButton(
onPressed: onYesPressed,
child: const Text("Yes"),
),
FlatButton(
child: Text("No"),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text("No"),
)
],
);

View File

@ -7,11 +7,12 @@ class ColorPickerButton extends StatelessWidget {
final Color selectedColor;
final void Function(Color) onColorPicked;
ColorPickerButton({
@required this.title,
@required this.dialogTitle,
@required this.selectedColor,
@required this.onColorPicked,
const ColorPickerButton({
super.key,
required this.title,
required this.dialogTitle,
required this.selectedColor,
required this.onColorPicked,
});
@override
@ -34,13 +35,13 @@ class ColorPickerButton extends StatelessWidget {
},
);
},
child: Text(title),
style: TextButton.styleFrom(
primary: useBrightBackground(selectedColor)
? appTheme.primaryTextTheme.button.color
: appTheme.textTheme.button.color,
foregroundColor: useBrightBackground(selectedColor)
? appTheme.primaryTextTheme.labelLarge?.color
: appTheme.textTheme.labelLarge?.color,
backgroundColor: selectedColor,
),
child: Text(title),
);
}
}

View File

@ -4,15 +4,17 @@ import 'package:time_progress_tracker/screens/progress_creation_screen.dart';
class CreateProgressButton extends StatelessWidget {
final String _heroTag = "createProgressBTN";
const CreateProgressButton({super.key});
@override
Widget build(BuildContext context) {
void _onButtonPressed() =>
void onButtonPressed() =>
Navigator.pushNamed(context, ProgressCreationScreen.routeName);
return FloatingActionButton(
heroTag: _heroTag,
child: Icon(Icons.add),
onPressed: _onButtonPressed,
onPressed: onButtonPressed,
child: const Icon(Icons.add),
);
}
}

View File

@ -3,13 +3,14 @@ import 'package:flutter/material.dart';
class DatePickerBtn extends StatelessWidget {
final String leadingString;
final DateTime pickedDate;
final void Function(DateTime) onDatePicked;
final void Function(DateTime?) onDatePicked;
DatePickerBtn({
@required this.leadingString,
@required this.pickedDate,
@required this.onDatePicked,
}) : super();
const DatePickerBtn({
super.key,
required this.leadingString,
required this.pickedDate,
required this.onDatePicked,
});
void _onButtonPressed(BuildContext context) async {
onDatePicked(await showDatePicker(
@ -25,12 +26,12 @@ class DatePickerBtn extends StatelessWidget {
ThemeData appTheme = Theme.of(context);
return TextButton(
onPressed: () => _onButtonPressed(context),
style: TextButton.styleFrom(
foregroundColor: appTheme.primaryTextTheme.labelLarge?.color,
backgroundColor: appTheme.colorScheme.secondary,
),
child: Text(
"$leadingString ${pickedDate.toLocal().toString().split(" ")[0]}"),
style: TextButton.styleFrom(
primary: appTheme.primaryTextTheme.button.color,
backgroundColor: appTheme.accentColor,
),
);
}
}

View File

@ -5,9 +5,10 @@ class SelectDurationBtn extends StatelessWidget {
final Duration duration;
final void Function(Duration) updateDuration;
SelectDurationBtn({
@required this.duration,
@required this.updateDuration,
const SelectDurationBtn({
super.key,
required this.duration,
required this.updateDuration,
});
void _onPickerConfirm(Picker picker, List<int> values) {
@ -25,7 +26,7 @@ class SelectDurationBtn extends StatelessWidget {
]),
hideHeader: false,
title: const Text("Default Duration"),
selectedTextStyle: TextStyle(color: appTheme.accentColor),
selectedTextStyle: TextStyle(color: appTheme.colorScheme.secondary),
onConfirm: _onPickerConfirm)
.showModal(context);
@ -38,10 +39,10 @@ class SelectDurationBtn extends StatelessWidget {
int days = duration.inDays - (365 * years) - (30 * months);
return TextButton(
onPressed: () => _onButtonPressed(context, appTheme),
child: Text("$years Years $months Months $days Days"),
style: TextButton.styleFrom(
primary: appTheme.primaryTextTheme.button.color,
backgroundColor: appTheme.accentColor,
));
foregroundColor: appTheme.primaryTextTheme.labelLarge?.color,
backgroundColor: appTheme.colorScheme.secondary,
),
child: Text("$years Years $months Months $days Days"));
}
}

View File

@ -10,25 +10,26 @@ class DetailScreenFloatingActionButtons extends StatelessWidget {
onCancelEditProgress,
onDeleteProgress;
DetailScreenFloatingActionButtons({
@required this.editMode,
@required this.originalProgress,
@required this.editedProgress,
@required this.isEditedProgressValid,
@required this.onEditProgress,
@required this.onSaveEditedProgress,
@required this.onCancelEditProgress,
@required this.onDeleteProgress,
const DetailScreenFloatingActionButtons({
super.key,
required this.editMode,
required this.originalProgress,
required this.editedProgress,
required this.isEditedProgressValid,
required this.onEditProgress,
required this.onSaveEditedProgress,
required this.onCancelEditProgress,
required this.onDeleteProgress,
});
@override
Widget build(BuildContext context) {
final ThemeData appTheme = Theme.of(context);
void _onCancelEditTimeProgressBTN() {
if (originalProgress == editedProgress)
void onCancelEditTimeProgressBTN() {
if (originalProgress == editedProgress) {
onCancelEditProgress();
else {
} else {
showDialog(
context: context,
builder: (_) => AppYesNoDialog(
@ -44,7 +45,7 @@ class DetailScreenFloatingActionButtons extends StatelessWidget {
}
}
void _onDeleteTimeProgressBTN() {
void onDeleteTimeProgressBTN() {
showDialog(
context: context,
builder: (_) => AppYesNoDialog(
@ -61,13 +62,13 @@ class DetailScreenFloatingActionButtons extends StatelessWidget {
child: FloatingActionButton(
heroTag:
editMode ? "saveEditedTimeProgressBTN" : "editTimeProgressBTN",
child: editMode ? Icon(Icons.save) : Icon(Icons.edit),
backgroundColor: editMode ? Colors.green : appTheme.accentColor,
backgroundColor: editMode ? Colors.green : appTheme.colorScheme.secondary,
onPressed: editMode
? isEditedProgressValid
? onSaveEditedProgress
: null
: onEditProgress,
child: editMode ? const Icon(Icons.save) : const Icon(Icons.edit),
),
),
Expanded(
@ -75,11 +76,11 @@ class DetailScreenFloatingActionButtons extends StatelessWidget {
heroTag: editMode
? "cancelEditTimeProgressBTN"
: "deleteTimeProgressBTN",
child: editMode ? Icon(Icons.cancel) : Icon(Icons.delete),
backgroundColor: Colors.red,
onPressed: editMode
? _onCancelEditTimeProgressBTN
: _onDeleteTimeProgressBTN,
? onCancelEditTimeProgressBTN
: onDeleteTimeProgressBTN,
child: editMode ? const Icon(Icons.cancel) : const Icon(Icons.delete),
),
),
],

View File

@ -2,13 +2,13 @@ import 'package:flutter/material.dart';
class HomeBottomNavBar extends StatelessWidget {
final int currentIndex;
final Function onTap;
final void Function(int)? onTap;
HomeBottomNavBar({
Key key,
@required this.currentIndex,
@required this.onTap,
}) : super(key: key);
const HomeBottomNavBar({
super.key,
required this.currentIndex,
required this.onTap,
});
@override
Widget build(BuildContext context) {
@ -19,21 +19,21 @@ class HomeBottomNavBar extends StatelessWidget {
currentIndex: currentIndex,
items: [
BottomNavigationBarItem(
icon: new Icon(
icon: Icon(
Icons.alarm,
color: appTheme.primaryColor,
),
label: "Active Progresses",
),
BottomNavigationBarItem(
icon: new Icon(
icon: Icon(
Icons.alarm_off,
color: appTheme.primaryColor,
),
label: "Inactive Progresses",
),
BottomNavigationBarItem(
icon: new Icon(
icon: Icon(
Icons.settings,
color: appTheme.primaryColor,
),

View File

@ -6,6 +6,8 @@ import 'package:time_progress_tracker/widgets/store_connectors/settings_store_co
import 'package:time_progress_tracker/widgets/store_connectors/time_progress_list_store_connector.dart';
class HomeActiveProgressesTab extends StatelessWidget {
const HomeActiveProgressesTab({super.key});
@override
Widget build(BuildContext context) {
return SettingsStoreConnector(
@ -14,14 +16,15 @@ class HomeActiveProgressesTab extends StatelessWidget {
loadedBuilder: (context, tpListVm) {
List<TimeProgress> activeTpList =
selectActiveProgresses(tpListVm.tpList);
if (activeTpList.length < 1)
if (activeTpList.isEmpty) {
return Container(
padding: EdgeInsets.all(16),
child: Center(
padding: const EdgeInsets.all(16),
child: const Center(
child: Text(
"You don't have any active time progress, that are tracked."),
),
);
}
return ProgressListView(
timeProgressList: activeTpList,

View File

@ -6,6 +6,8 @@ import 'package:time_progress_tracker/widgets/store_connectors/settings_store_co
import 'package:time_progress_tracker/widgets/store_connectors/time_progress_list_store_connector.dart';
class HomeInactiveProgressesTab extends StatelessWidget {
const HomeInactiveProgressesTab({super.key});
@override
Widget build(BuildContext context) {
return SettingsStoreConnector(
@ -14,14 +16,15 @@ class HomeInactiveProgressesTab extends StatelessWidget {
loadedBuilder: (context, tpListVm) {
List<TimeProgress> inactiveTpList =
selectInactiveProgresses(tpListVm.tpList);
if (inactiveTpList.length < 1)
if (inactiveTpList.isEmpty) {
return Container(
padding: EdgeInsets.all(16),
child: Center(
padding: const EdgeInsets.all(16),
child: const Center(
child: Text(
"You don't have any currently inactive time progresses, that are tracked."),
),
);
}
return ProgressListView(
timeProgressList: inactiveTpList,

View File

@ -5,12 +5,14 @@ import 'package:time_progress_tracker/widgets/home/tabs/settings/duration_settin
import 'package:time_progress_tracker/widgets/store_connectors/settings_store_connector.dart';
class HomeSettingsTab extends StatelessWidget {
const HomeSettingsTab({super.key});
@override
Widget build(BuildContext context) {
return SettingsStoreConnector(
loadedBuilder: (context, settingsVm) {
return Container(
padding: EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
child: Center(
child: Column(
children: [
@ -28,7 +30,7 @@ class HomeSettingsTab extends StatelessWidget {
updateDuration: settingsVm.updateDuration,
),
),
Spacer(),
const Spacer(),
Expanded(
child: TextButton(
onPressed: () {
@ -39,7 +41,7 @@ class HomeSettingsTab extends StatelessWidget {
applicationLegalese:
'\u00a9Andreas Fahrecker 2020-2021');
},
child: Text("About"),
child: const Text("About"),
),
),
],

View File

@ -5,11 +5,12 @@ class ColorSettingsWidget extends StatelessWidget {
final Color doneColor, leftColor;
final void Function(Color) updateDoneColor, updateLeftColor;
ColorSettingsWidget({
@required this.doneColor,
@required this.leftColor,
@required this.updateDoneColor,
@required this.updateLeftColor,
const ColorSettingsWidget({
super.key,
required this.doneColor,
required this.leftColor,
required this.updateDoneColor,
required this.updateLeftColor,
});
@override
@ -21,14 +22,14 @@ class ColorSettingsWidget extends StatelessWidget {
Expanded(
child: Text(
"Color Settings",
style: appTheme.textTheme.headline6,
style: appTheme.textTheme.titleLarge,
),
),
Row(
children: [
Expanded(
child: Padding(
padding: EdgeInsets.only(right: 5),
padding: const EdgeInsets.only(right: 5),
child: ColorPickerButton(
title: "Done Color",
dialogTitle: "Select Done Color",
@ -39,7 +40,7 @@ class ColorSettingsWidget extends StatelessWidget {
),
Expanded(
child: Padding(
padding: EdgeInsets.only(left: 5),
padding: const EdgeInsets.only(left: 5),
child: ColorPickerButton(
title: "Left Color",
dialogTitle: "Select Left Color",

View File

@ -5,24 +5,25 @@ class DurationSettingsWidget extends StatelessWidget {
final Duration duration;
final void Function(Duration) updateDuration;
DurationSettingsWidget({
@required this.duration,
@required this.updateDuration,
const DurationSettingsWidget({
super.key,
required this.duration,
required this.updateDuration,
});
@override
Widget build(BuildContext context) {
ThemeData appTheme = Theme.of(context);
int years = duration.inDays ~/ 365;
int months = (duration.inDays - (365 * years)) ~/ 30;
int days = duration.inDays - (365 * years) - (30 * months);
//int years = duration.inDays ~/ 365;
//int months = (duration.inDays - (365 * years)) ~/ 30;
//int days = duration.inDays - (365 * years) - (30 * months);
return Column(
children: [
Expanded(
child: Text(
"Duration Settings",
style: appTheme.textTheme.headline6,
style: appTheme.textTheme.titleLarge,
),
),
Row(

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:time_progress_tracker/models/time_progress.dart';
import 'package:time_progress_tracker/widgets/buttons/date_picker_btn.dart';
@ -6,9 +7,10 @@ class ProgressEditorWidget extends StatefulWidget {
final TimeProgress timeProgress;
final Function(TimeProgress, bool) onTimeProgressChanged;
ProgressEditorWidget({
@required this.timeProgress,
@required this.onTimeProgressChanged,
const ProgressEditorWidget({
super.key,
required this.timeProgress,
required this.onTimeProgressChanged,
});
@override
@ -31,7 +33,10 @@ class _ProgressEditorWidgetState extends State<ProgressEditorWidget> {
});
}
void _onStartDateChanged(DateTime newStartDate) {
void _onStartDateChanged(DateTime? newStartDate) {
if (newStartDate == null) {
return;
}
TimeProgress newProgress =
widget.timeProgress.copyWith(startTime: newStartDate);
widget.onTimeProgressChanged(
@ -42,7 +47,10 @@ class _ProgressEditorWidgetState extends State<ProgressEditorWidget> {
});
}
void _onEndDateChanged(DateTime newEndDate) {
void _onEndDateChanged(DateTime? newEndDate) {
if (newEndDate == null) {
return;
}
TimeProgress newProgress =
widget.timeProgress.copyWith(endTime: newEndDate);
widget.onTimeProgressChanged(
@ -62,12 +70,15 @@ class _ProgressEditorWidgetState extends State<ProgressEditorWidget> {
@override
Widget build(BuildContext context) {
double heightFactor = (!_validDate) ? 0.3 : 0.5;
List<Widget> columnChildren = [
Expanded(
SizedBox(
height: MediaQuery.of(context).size.height * heightFactor,
child: TextField(
controller: _nameTextController,
decoration: InputDecoration(
border: OutlineInputBorder(),
border: const OutlineInputBorder(),
labelText: "Progress Name",
errorText: _validName
? null
@ -75,12 +86,13 @@ class _ProgressEditorWidgetState extends State<ProgressEditorWidget> {
),
),
),
Expanded(
SizedBox(
height: MediaQuery.of(context).size.height * heightFactor,
child: Row(
children: [
Expanded(
child: Padding(
padding: EdgeInsets.only(right: 5),
padding: const EdgeInsets.only(right: 5),
child: DatePickerBtn(
leadingString: "Start Date:",
pickedDate: widget.timeProgress.startTime,
@ -90,7 +102,7 @@ class _ProgressEditorWidgetState extends State<ProgressEditorWidget> {
),
Expanded(
child: Padding(
padding: EdgeInsets.only(left: 5),
padding: const EdgeInsets.only(left: 5),
child: DatePickerBtn(
leadingString: "End Date:",
pickedDate: widget.timeProgress.endTime,
@ -103,10 +115,11 @@ class _ProgressEditorWidgetState extends State<ProgressEditorWidget> {
)
];
if (!_validDate)
if (!_validDate) {
columnChildren.add(
Expanded(
child: Center(
SizedBox(
height: MediaQuery.of(context).size.height * heightFactor,
child: const Center(
child: Text(
"Invalid Dates. The Start Date has to be before the End Date",
style: TextStyle(color: Colors.red),
@ -114,8 +127,10 @@ class _ProgressEditorWidgetState extends State<ProgressEditorWidget> {
),
),
);
}
return Container(
return SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: Column(
children: columnChildren,
),

View File

@ -18,17 +18,19 @@ class ProgressListTile extends StatelessWidget {
final TimeProgress timeProgress;
final Color doneColor, leftColor;
ProgressListTile({
@required this.timeProgress,
@required this.doneColor,
@required this.leftColor,
const ProgressListTile({super.key,
required this.timeProgress,
required this.doneColor,
required this.leftColor,
});
Widget _renderSubtitle(BuildContext context) {
if (!timeProgress.hasStarted())
if (!timeProgress.hasStarted()) {
return Text(ProgressListTileStrings.startsInDaysString(timeProgress));
if (timeProgress.hasEnded())
}
if (timeProgress.hasEnded()) {
return Text(ProgressListTileStrings.endedDaysAgoString(timeProgress));
}
return LinearPercentIndicator(
center: Text(ProgressListTileStrings.percentString(timeProgress)),
percent: timeProgress.percentDone(),
@ -40,14 +42,14 @@ class ProgressListTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
void _onTileTap() =>
void onTileTap() =>
Navigator.pushNamed(context, ProgressDetailScreen.routeName,
arguments: ProgressDetailScreenArguments(timeProgress.id));
return ListTile(
title: Text(timeProgress.name),
subtitle: _renderSubtitle(context),
onTap: _onTileTap,
onTap: onTileTap,
);
}
}

View File

@ -6,10 +6,11 @@ class ProgressListView extends StatelessWidget {
final List<TimeProgress> timeProgressList;
final Color doneColor, leftColor;
ProgressListView({
@required this.timeProgressList,
@required this.doneColor,
@required this.leftColor,
const ProgressListView({
super.key,
required this.timeProgressList,
required this.doneColor,
required this.leftColor,
});
List<Widget> _renderListViewChildren() {
@ -27,7 +28,7 @@ class ProgressListView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView(
padding: EdgeInsets.all(8),
padding: const EdgeInsets.all(8),
children: _renderListViewChildren(),
);
}

View File

@ -8,31 +8,37 @@ class ProgressViewWidget extends StatelessWidget {
final Color doneColor;
final Color leftColor;
ProgressViewWidget({
@required this.timeProgress,
@required this.doneColor,
@required this.leftColor,
const ProgressViewWidget({
super.key,
required this.timeProgress,
required this.doneColor,
required this.leftColor,
});
@override
Widget build(BuildContext context) {
return Container(
return SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: Column(
children: [
Expanded(
SizedBox(
height: MediaQuery.of(context).size.height *
0.3, // adjust the value as needed
child: FittedBox(
fit: BoxFit.fitWidth,
child: Text(
timeProgress.name,
textAlign: TextAlign.center,
style: TextStyle(
style: const TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black87,
),
),
),
),
Expanded(
SizedBox(
height: MediaQuery.of(context).size.height *
0.3, // adjust the value as needed
child: CircularPercentIndicator(
radius: 100,
lineWidth: 10,
@ -42,14 +48,16 @@ class ProgressViewWidget extends StatelessWidget {
center: Text("${(timeProgress.percentDone() * 100).floor()} %"),
),
),
Expanded(
SizedBox(
height: MediaQuery.of(context).size.height *
0.3, // adjust the value as needed
child: LinearPercentIndicator(
padding: EdgeInsets.symmetric(horizontal: 15),
padding: const EdgeInsets.symmetric(horizontal: 15),
percent: timeProgress.percentDone(),
leading: Text("${timeProgress.daysBehind()} Days"),
center: Text(
"${(timeProgress.percentDone() * 100).floor()} %",
style: TextStyle(color: Colors.white),
style: const TextStyle(color: Colors.white),
),
trailing: Text("${timeProgress.daysLeft()} Days"),
progressColor: doneColor,

View File

@ -8,8 +8,9 @@ import 'package:time_progress_tracker/models/app_state.dart';
class SettingsStoreConnector extends StatelessWidget {
final Widget Function(BuildContext, SettingsViewModel) loadedBuilder;
SettingsStoreConnector({
@required this.loadedBuilder,
const SettingsStoreConnector({
super.key,
required this.loadedBuilder,
});
@override
@ -18,10 +19,11 @@ class SettingsStoreConnector extends StatelessWidget {
onInit: loadSettingsIfUnloaded,
converter: (store) => SettingsViewModel._create(store),
builder: (context, SettingsViewModel vm) {
if (!vm.hasSettingsLoaded)
return Center(
if (!vm.hasSettingsLoaded) {
return const Center(
child: CircularProgressIndicator(),
);
}
return loadedBuilder(context, vm);
},
);
@ -44,17 +46,17 @@ class SettingsViewModel {
);
factory SettingsViewModel._create(Store<AppState> store) {
AppSettings _appSettings = store.state.appSettings;
AppSettings appSettings = store.state.appSettings;
void _updateDoneColor(Color dC) => store.dispatch(
UpdateAppSettingsActions(_appSettings.copyWith(doneColor: dC)));
void _updateLeftColor(Color lC) => store.dispatch(
UpdateAppSettingsActions(_appSettings.copyWith(leftColor: lC)));
void updateDoneColor(Color dC) => store.dispatch(
UpdateAppSettingsActions(appSettings.copyWith(doneColor: dC)));
void updateLeftColor(Color lC) => store.dispatch(
UpdateAppSettingsActions(appSettings.copyWith(leftColor: lC)));
void _updateDuration(Duration d) => store
.dispatch(UpdateAppSettingsActions(_appSettings.copyWith(duration: d)));
void updateDuration(Duration d) => store
.dispatch(UpdateAppSettingsActions(appSettings.copyWith(duration: d)));
return SettingsViewModel(_appSettings, store.state.hasSettingsLoaded,
_updateDoneColor, _updateLeftColor, _updateDuration);
return SettingsViewModel(appSettings, store.state.hasSettingsLoaded,
updateDoneColor, updateLeftColor, updateDuration);
}
}

View File

@ -8,8 +8,9 @@ import 'package:time_progress_tracker/models/time_progress.dart';
class TimeProgressListStoreConnector extends StatelessWidget {
final Widget Function(BuildContext, TimeProgressListViewModel) loadedBuilder;
TimeProgressListStoreConnector({
@required this.loadedBuilder,
const TimeProgressListStoreConnector({
super.key,
required this.loadedBuilder,
});
@override
@ -18,10 +19,11 @@ class TimeProgressListStoreConnector extends StatelessWidget {
onInit: loadTimeProgressListIfUnloaded,
converter: (store) => TimeProgressListViewModel._create(store),
builder: (context, TimeProgressListViewModel vm) {
if (!vm.hasTpListLoaded)
return Center(
if (!vm.hasTpListLoaded) {
return const Center(
child: CircularProgressIndicator(),
);
}
return loadedBuilder(context, vm);
},
);

View File

@ -11,9 +11,10 @@ class TimeProgressStoreConnector extends StatelessWidget {
final String timeProgressId;
final Widget Function(BuildContext, TimeProgressViewModel) loadedBuilder;
TimeProgressStoreConnector({
@required this.timeProgressId,
@required this.loadedBuilder,
const TimeProgressStoreConnector({
super.key,
required this.timeProgressId,
required this.loadedBuilder,
});
@override
@ -23,14 +24,11 @@ class TimeProgressStoreConnector extends StatelessWidget {
converter: (store) =>
TimeProgressViewModel._create(store, timeProgressId),
builder: (context, TimeProgressViewModel vm) {
if (!vm.hasTpListLoaded)
return Center(
if (!vm.hasTpListLoaded) {
return const Center(
child: CircularProgressIndicator(),
);
if (vm.tp == null)
return Center(
child: Text("Error Invalid Time Progress"),
);
}
return loadedBuilder(context, vm);
},
);
@ -52,15 +50,15 @@ class TimeProgressViewModel {
);
factory TimeProgressViewModel._create(Store<AppState> store, String id) {
void _updateTimeProgress(TimeProgress tp) =>
void updateTimeProgress(TimeProgress tp) =>
store.dispatch(UpdateTimeProgressAction(id, tp));
void _deleteTimeProgress() => store.dispatch(DeleteTimeProgressAction(id));
void deleteTimeProgress() => store.dispatch(DeleteTimeProgressAction(id));
return TimeProgressViewModel(
selectProgressById(store.state.timeProgressList, id),
store.state.hasProgressesLoaded,
_updateTimeProgress,
_deleteTimeProgress,
updateTimeProgress,
deleteTimeProgress,
);
}
}

View File

@ -109,18 +109,18 @@ packages:
dependency: transitive
description:
name: ffi
sha256: d97fffd9d86f3dccc7a9059128b468a99320c69007cc9d41a3a1bda07d4e86dc
sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
version: "2.1.2"
file:
dependency: transitive
description:
name: file
sha256: "9fd2163d866769f60f4df8ac1dc59f52498d810c356fe78022e383dd3c57c0e1"
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
url: "https://pub.dev"
source: hosted
version: "6.1.0"
version: "7.0.0"
flutter:
dependency: "direct main"
description: flutter
@ -189,10 +189,10 @@ packages:
dependency: transitive
description:
name: js
sha256: d9bdfd70d828eeb352390f81b18d6a354ef2044aa28ef25682079797fa7cd174
sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
url: "https://pub.dev"
source: hosted
version: "0.6.3"
version: "0.7.1"
json_annotation:
dependency: transitive
description:
@ -269,26 +269,26 @@ packages:
dependency: transitive
description:
name: path_provider_linux
sha256: "938d2b6591587bcb009d2109a6ea464fd8fb2a75dc6423171b0d0afb1d27c708"
sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "2.2.1"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
sha256: "2e14fc474b8acfc4111ac8eb0e37c2fe70234f9f8cd796f1560d03aa1689fa51"
sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "2.1.2"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
sha256: ecd4d04c225596bcf0fbb86408a1f40084a02dfa412e60172ad52a7f12a781ef
sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "2.2.1"
percent_indicator:
dependency: "direct main"
description:
@ -309,18 +309,18 @@ packages:
dependency: transitive
description:
name: platform
sha256: ebc79f16b5f6b609aad4a5e63447d4795d16f7adee46e93ed03200848c006735
sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
version: "3.1.4"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: c2c49e16d42fd6983eb55e44b7f197fdf16b4da7aab7f8e1d21da307cad3fb02
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "2.1.8"
pointycastle:
dependency: transitive
description:
@ -329,14 +329,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.7.4"
process:
dependency: transitive
description:
name: process
sha256: c7b9f7d8a6ee4407ab4f8a7d4a951f8f5659c40df14c0924e2e97c32372e9b14
url: "https://pub.dev"
source: hosted
version: "4.1.0"
redux:
dependency: "direct main"
description:
@ -349,50 +341,58 @@ packages:
dependency: "direct main"
description:
name: shared_preferences
sha256: "2ead304936605c686c0c1a5ce3d9771dbc2e60d76db68b9cd313eb860ca8f9e3"
sha256: "81429e4481e1ccfb51ede496e916348668fd0921627779233bd24cc3ff6abd02"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "2.2.2"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
sha256: "8568a389334b6e83415b6aae55378e158fbc2314e074983362d20c562780fb06"
url: "https://pub.dev"
source: hosted
version: "2.2.1"
shared_preferences_foundation:
dependency: transitive
description:
name: shared_preferences_foundation
sha256: "7708d83064f38060c7b39db12aefe449cb8cdc031d6062280087bc4cdb988f5c"
url: "https://pub.dev"
source: hosted
version: "2.3.5"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
sha256: "33fc7c6ced70d226645a9612132fbff9890805df4edd34f30840e7e738866fee"
sha256: "9f2cbcf46d4270ea8be39fa156d86379077c8a5228d9dfdb1164ae0bb93f1faa"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
shared_preferences_macos:
dependency: transitive
description:
name: shared_preferences_macos
sha256: "5d2bad07b196b6ad4cf21af6f7197a87264ef569199502b9352f76e5054f06ae"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "2.3.2"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
sha256: "992f0fdc46d0a3c0ac2e5859f2de0e577bbe51f78a77ee8f357cbe626a2ad32d"
sha256: "22e2ecac9419b4246d7c22bfbbda589e3acf5c0351137d87dd2939d984d37c3b"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "2.3.2"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
sha256: "09b72ec530a1b1f26cdbec6b138f980d97d4d86ebb86dbf6365369fbd4bb05c8"
sha256: "9aee1089b36bd2aafe06582b7d7817fd317ef05fc30e6ba14bff247d0933042a"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "2.3.0"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
sha256: "76c54a0148780d779a3fe332ece9ba8ad2c9dd0bc717ee7fce58bd06b5e8118f"
sha256: "841ad54f3c8381c480d0c9b508b89a34036f512482c407e6df7a9c4aa2ef8f59"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "2.3.2"
sky_engine:
dependency: transitive
description: flutter
@ -450,10 +450,10 @@ packages:
dependency: transitive
description:
name: typed_data
sha256: "53bdf7e979cfbf3e28987552fd72f637e63f3c8724c9e56d9246942dc2fa36ee"
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
url: "https://pub.dev"
source: hosted
version: "1.3.0"
version: "1.3.2"
vector_math:
dependency: transitive
description:
@ -470,22 +470,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "13.0.0"
web:
dependency: transitive
description:
name: web
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
win32:
dependency: transitive
description:
name: win32
sha256: c6a3f4e4058b70b46e27b2935de2d1562c50680e7fb44833911d981db73826c2
sha256: "8cb58b45c47dcb42ab3651533626161d6b67a2921917d8d429791f76972b3480"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "5.3.0"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
sha256: "0186b3f2d66be9a12b0295bddcf8b6f8c0b0cc2f85c6287344e2a6366bc28457"
sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "1.0.4"
xml:
dependency: transitive
description:
@ -504,4 +512,4 @@ packages:
version: "3.1.2"
sdks:
dart: ">=3.3.1 <4.0.0"
flutter: ">=2.12.0"
flutter: ">=3.19.0"

View File

@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.0.19+19
version: 0.0.21+21
environment:
sdk: '>=3.3.1 <4.0.0'

View File

@ -3,8 +3,9 @@ import 'package:flutter/material.dart';
class MaterialTesterWidget extends StatelessWidget {
final Widget widget;
MaterialTesterWidget({
@required this.widget,
const MaterialTesterWidget({
super.key,
required this.widget,
});
@override

View File

@ -13,34 +13,34 @@ import 'package:time_progress_tracker/models/time_progress.dart';
import 'package:time_progress_tracker/widgets/progress_list_view/progress_list_tile.dart';
import 'package:time_progress_tracker/widgets/progress_list_view/progress_list_view.dart';
import 'MaterialTesterWidget.dart';
import 'material_tester_widget.dart';
void main() {
final AppSettings _defaultAppSettings = AppSettings.defaults();
final int _thisYear = DateTime.now().year;
final TimeProgress _activeProgress = TimeProgress(
"TestProgress", DateTime(_thisYear - 2), DateTime(_thisYear + 2));
final AppSettings defaultAppSettings = AppSettings.defaults();
final int thisYear = DateTime.now().year;
final TimeProgress activeProgress = TimeProgress(
"TestProgress", DateTime(thisYear - 2), DateTime(thisYear + 2));
void _findStringOnce(String str) => expect(find.text(str), findsOneWidget);
void findStringOnce(String str) => expect(find.text(str), findsOneWidget);
testWidgets("Progress List Tile with currently active progress works",
(WidgetTester tester) async {
await tester.pumpWidget(MaterialTesterWidget(
widget: ProgressListTile(
timeProgress: _activeProgress,
doneColor: _defaultAppSettings.doneColor,
leftColor: _defaultAppSettings.leftColor,
timeProgress: activeProgress,
doneColor: defaultAppSettings.doneColor,
leftColor: defaultAppSettings.leftColor,
),
));
_findStringOnce(_activeProgress.name);
_findStringOnce(ProgressListTileStrings.percentString(_activeProgress));
findStringOnce(activeProgress.name);
findStringOnce(ProgressListTileStrings.percentString(activeProgress));
WidgetPredicate linearPercentPredicate = (Widget widget) =>
linearPercentPredicate(Widget widget) =>
widget is LinearPercentIndicator &&
widget.percent == _activeProgress.percentDone() &&
widget.progressColor == _defaultAppSettings.doneColor &&
widget.backgroundColor == _defaultAppSettings.leftColor;
widget.percent == activeProgress.percentDone() &&
widget.progressColor == defaultAppSettings.doneColor &&
widget.backgroundColor == defaultAppSettings.leftColor;
expect(find.byWidgetPredicate(linearPercentPredicate), findsOneWidget);
});
@ -48,40 +48,40 @@ void main() {
(WidgetTester tester) async {
TimeProgress futureProgress = TimeProgress(
"Test Progress",
DateTime(_thisYear + 1),
DateTime(_thisYear + 2),
DateTime(thisYear + 1),
DateTime(thisYear + 2),
);
await tester.pumpWidget(MaterialTesterWidget(
widget: ProgressListTile(
timeProgress: futureProgress,
doneColor: _defaultAppSettings.doneColor,
leftColor: _defaultAppSettings.leftColor,
doneColor: defaultAppSettings.doneColor,
leftColor: defaultAppSettings.leftColor,
),
));
_findStringOnce(futureProgress.name);
_findStringOnce(ProgressListTileStrings.startsInDaysString(futureProgress));
findStringOnce(futureProgress.name);
findStringOnce(ProgressListTileStrings.startsInDaysString(futureProgress));
});
testWidgets("Progress List Tile with past progress works",
(WidgetTester tester) async {
TimeProgress pastProgress = TimeProgress(
"Test Progress",
DateTime(_thisYear - 2),
DateTime(_thisYear - 1),
DateTime(thisYear - 2),
DateTime(thisYear - 1),
);
await tester.pumpWidget(MaterialTesterWidget(
widget: ProgressListTile(
timeProgress: pastProgress,
doneColor: _defaultAppSettings.doneColor,
leftColor: _defaultAppSettings.leftColor,
doneColor: defaultAppSettings.doneColor,
leftColor: defaultAppSettings.leftColor,
),
));
_findStringOnce(pastProgress.name);
_findStringOnce(ProgressListTileStrings.endedDaysAgoString(pastProgress));
findStringOnce(pastProgress.name);
findStringOnce(ProgressListTileStrings.endedDaysAgoString(pastProgress));
});
WidgetPredicate getProgressListTilePredicate(
@ -96,35 +96,37 @@ void main() {
(WidgetTester tester) async {
await tester.pumpWidget(MaterialTesterWidget(
widget: ProgressListView(
timeProgressList: [_activeProgress],
doneColor: _defaultAppSettings.doneColor,
leftColor: _defaultAppSettings.leftColor,
timeProgressList: [activeProgress],
doneColor: defaultAppSettings.doneColor,
leftColor: defaultAppSettings.leftColor,
),
));
_findStringOnce(_activeProgress.name);
findStringOnce(activeProgress.name);
expect(
find.byWidgetPredicate(
getProgressListTilePredicate(_activeProgress, _defaultAppSettings)),
getProgressListTilePredicate(activeProgress, defaultAppSettings)),
findsOneWidget);
});
testWidgets("Progress List View displays file tiles",
(WidgetTester tester) async {
List<TimeProgress> tpList = [];
for (int i = 0; i < 5; i++) tpList.add(_activeProgress);
for (int i = 0; i < 5; i++) {
tpList.add(activeProgress);
}
await tester.pumpWidget(MaterialTesterWidget(
widget: ProgressListView(
timeProgressList: tpList,
doneColor: _defaultAppSettings.doneColor,
leftColor: _defaultAppSettings.leftColor,
doneColor: defaultAppSettings.doneColor,
leftColor: defaultAppSettings.leftColor,
),
));
expect(find.text(_activeProgress.name), findsNWidgets(5));
expect(find.text(activeProgress.name), findsNWidgets(5));
expect(
find.byWidgetPredicate(
getProgressListTilePredicate(_activeProgress, _defaultAppSettings)),
getProgressListTilePredicate(activeProgress, defaultAppSettings)),
findsNWidgets(5));
});
}