Feature/code cleanup (#9)
* Implemented hasSettingsLoaded reducer * Added Padding to Progress List View * Created Settings and Time Progress List Store Connector * Rewritten Home Active Tab * Fixed missing onTap in Progress List Tile * Started using new Store Connectors in Inactive and Settings Tab * Created Time Progress Store Connector * Rewritten ProgressDetailScreen with new Store Connectors * Rewritten DatePickerBtn with TextButton * Deleted unused widget * Changed Foreground Color behaviour in ColorPicker BTN * Created Select Duration Button * Rewritten Duration Setting Widget * Updated Version Number Signed-off-by: Andreas Fahrecker <AndreasFahrecker@gmail.com>
This commit is contained in:
committed by
GitHub
parent
fc35476503
commit
40bdcc44f9
60
lib/widgets/store_connectors/settings_store_connector.dart
Normal file
60
lib/widgets/store_connectors/settings_store_connector.dart
Normal file
@ -0,0 +1,60 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:redux/redux.dart';
|
||||
import 'package:time_progress_tracker/actions/actions.dart';
|
||||
import 'package:time_progress_tracker/models/app_settings.dart';
|
||||
import 'package:time_progress_tracker/models/app_state.dart';
|
||||
|
||||
class SettingsStoreConnector extends StatelessWidget {
|
||||
final Widget Function(BuildContext, SettingsViewModel) loadedBuilder;
|
||||
|
||||
SettingsStoreConnector({
|
||||
@required this.loadedBuilder,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StoreConnector<AppState, SettingsViewModel>(
|
||||
onInit: loadSettingsIfUnloaded,
|
||||
converter: (store) => SettingsViewModel._create(store),
|
||||
builder: (context, SettingsViewModel vm) {
|
||||
if (!vm.hasSettingsLoaded)
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
return loadedBuilder(context, vm);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SettingsViewModel {
|
||||
final AppSettings appSettings;
|
||||
final bool hasSettingsLoaded;
|
||||
|
||||
final void Function(Color) updateDoneColor, updateLeftColor;
|
||||
final void Function(Duration) updateDuration;
|
||||
|
||||
SettingsViewModel(
|
||||
this.appSettings,
|
||||
this.hasSettingsLoaded,
|
||||
this.updateDoneColor,
|
||||
this.updateLeftColor,
|
||||
this.updateDuration,
|
||||
);
|
||||
|
||||
factory SettingsViewModel._create(Store<AppState> store) {
|
||||
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 _updateDuration(Duration d) => store
|
||||
.dispatch(UpdateAppSettingsActions(_appSettings.copyWith(duration: d)));
|
||||
|
||||
return SettingsViewModel(_appSettings, store.state.hasSettingsLoaded,
|
||||
_updateDoneColor, _updateLeftColor, _updateDuration);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:redux/redux.dart';
|
||||
import 'package:time_progress_tracker/actions/actions.dart';
|
||||
import 'package:time_progress_tracker/models/app_state.dart';
|
||||
import 'package:time_progress_tracker/models/time_progress.dart';
|
||||
|
||||
class TimeProgressListStoreConnector extends StatelessWidget {
|
||||
final Widget Function(BuildContext, TimeProgressListViewModel) loadedBuilder;
|
||||
|
||||
TimeProgressListStoreConnector({
|
||||
@required this.loadedBuilder,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StoreConnector<AppState, TimeProgressListViewModel>(
|
||||
onInit: loadTimeProgressListIfUnloaded,
|
||||
converter: (store) => TimeProgressListViewModel._create(store),
|
||||
builder: (context, TimeProgressListViewModel vm) {
|
||||
if (!vm.hasTpListLoaded)
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
return loadedBuilder(context, vm);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TimeProgressListViewModel {
|
||||
final List<TimeProgress> tpList;
|
||||
final bool hasTpListLoaded;
|
||||
|
||||
TimeProgressListViewModel(this.tpList, this.hasTpListLoaded);
|
||||
|
||||
factory TimeProgressListViewModel._create(Store<AppState> store) =>
|
||||
TimeProgressListViewModel(
|
||||
store.state.timeProgressList, store.state.hasProgressesLoaded);
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:redux/redux.dart';
|
||||
import 'package:time_progress_tracker/actions/actions.dart';
|
||||
import 'package:time_progress_tracker/models/app_state.dart';
|
||||
import 'package:time_progress_tracker/models/time_progress.dart';
|
||||
|
||||
import '../../helper_functions.dart';
|
||||
|
||||
class TimeProgressStoreConnector extends StatelessWidget {
|
||||
final String timeProgressId;
|
||||
final Widget Function(BuildContext, TimeProgressViewModel) loadedBuilder;
|
||||
|
||||
TimeProgressStoreConnector({
|
||||
@required this.timeProgressId,
|
||||
@required this.loadedBuilder,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StoreConnector<AppState, TimeProgressViewModel>(
|
||||
onInit: loadTimeProgressListIfUnloaded,
|
||||
converter: (store) =>
|
||||
TimeProgressViewModel._create(store, timeProgressId),
|
||||
builder: (context, TimeProgressViewModel vm) {
|
||||
if (!vm.hasTpListLoaded)
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
if (vm.tp == null)
|
||||
return Center(
|
||||
child: Text("Error Invalid Time Progress"),
|
||||
);
|
||||
return loadedBuilder(context, vm);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TimeProgressViewModel {
|
||||
final TimeProgress tp;
|
||||
final bool hasTpListLoaded;
|
||||
|
||||
final void Function(TimeProgress) updateTimeProgress;
|
||||
final void Function() deleteTimeProgress;
|
||||
|
||||
TimeProgressViewModel(
|
||||
this.tp,
|
||||
this.hasTpListLoaded,
|
||||
this.updateTimeProgress,
|
||||
this.deleteTimeProgress,
|
||||
);
|
||||
|
||||
factory TimeProgressViewModel._create(Store<AppState> store, String id) {
|
||||
void _updateTimeProgress(TimeProgress tp) =>
|
||||
store.dispatch(UpdateTimeProgressAction(id, tp));
|
||||
void _deleteTimeProgress() => store.dispatch(DeleteTimeProgressAction(id));
|
||||
|
||||
return TimeProgressViewModel(
|
||||
selectProgressById(store.state.timeProgressList, id),
|
||||
store.state.hasProgressesLoaded,
|
||||
_updateTimeProgress,
|
||||
_deleteTimeProgress,
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user