Feature/default duration setting (#7)
* Implemented Basic Duration Settings into AppSettings Model * Implemented Basic Duration Settings into AppSettings Model * Created Duration Settings Widget and Started using ViewModel in HomeSettingsTab * Updated Version Number
This commit is contained in:
committed by
GitHub
parent
b520d56d1a
commit
90f2998088
@ -7,24 +7,15 @@ import 'package:time_progress_tracker/models/app_settings.dart';
|
||||
import 'package:time_progress_tracker/models/app_state.dart';
|
||||
import 'package:time_progress_tracker/selectors/time_progress_selectors.dart';
|
||||
import 'package:time_progress_tracker/widgets/home/tabs/settings/color_settings_widget.dart';
|
||||
import 'package:time_progress_tracker/widgets/home/tabs/settings/duration_settings_widget.dart';
|
||||
|
||||
class HomeSettingsTab extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StoreConnector<AppState, AppSettings>(
|
||||
return StoreConnector<AppState, _ViewModel>(
|
||||
onInit: loadSettingsIfUnloaded,
|
||||
converter: (store) => appSettingsSelector(store.state),
|
||||
builder: (context, AppSettings settings) {
|
||||
Store<AppState> store = StoreProvider.of<AppState>(context);
|
||||
void updateDoneColor(Color newDoneColor) => store.dispatch(
|
||||
UpdateAppSettingsActions(
|
||||
settings.copyWith(doneColor: newDoneColor)),
|
||||
);
|
||||
void updateLeftColor(Color newLeftColor) => store.dispatch(
|
||||
UpdateAppSettingsActions(
|
||||
settings.copyWith(leftColor: newLeftColor)),
|
||||
);
|
||||
|
||||
converter: (store) => _ViewModel.create(store),
|
||||
builder: (context, _ViewModel vm) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Center(
|
||||
@ -32,10 +23,16 @@ class HomeSettingsTab extends StatelessWidget {
|
||||
children: [
|
||||
Expanded(
|
||||
child: ColorSettingsWidget(
|
||||
doneColor: settings.doneColor,
|
||||
leftColor: settings.leftColor,
|
||||
updateDoneColor: updateDoneColor,
|
||||
updateLeftColor: updateLeftColor,
|
||||
doneColor: vm.doneColor,
|
||||
leftColor: vm.leftColor,
|
||||
updateDoneColor: vm.onDoneColorChanged,
|
||||
updateLeftColor: vm.onLeftColorChanged,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: DurationSettingsWidget(
|
||||
duration: vm.duration,
|
||||
updateDuration: vm.onDurationChanged,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
@ -60,3 +57,39 @@ class HomeSettingsTab extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ViewModel {
|
||||
final Color doneColor, leftColor;
|
||||
final void Function(Color) onDoneColorChanged, onLeftColorChanged;
|
||||
final Duration duration;
|
||||
final void Function(Duration) onDurationChanged;
|
||||
|
||||
_ViewModel({
|
||||
@required this.doneColor,
|
||||
@required this.leftColor,
|
||||
@required this.onDoneColorChanged,
|
||||
@required this.onLeftColorChanged,
|
||||
@required this.duration,
|
||||
@required this.onDurationChanged,
|
||||
});
|
||||
|
||||
factory _ViewModel.create(Store<AppState> store) {
|
||||
AppSettings settings = appSettingsSelector(store.state);
|
||||
|
||||
void _onDoneColorChanged(Color c) => store
|
||||
.dispatch(UpdateAppSettingsActions(settings.copyWith(doneColor: c)));
|
||||
void _onLeftColorChanged(Color c) => store
|
||||
.dispatch(UpdateAppSettingsActions(settings.copyWith(leftColor: c)));
|
||||
|
||||
void _onDurationChanged(Duration d) => store
|
||||
.dispatch(UpdateAppSettingsActions(settings.copyWith(duration: d)));
|
||||
|
||||
return _ViewModel(
|
||||
doneColor: settings.doneColor,
|
||||
leftColor: settings.leftColor,
|
||||
onDoneColorChanged: _onDoneColorChanged,
|
||||
onLeftColorChanged: _onLeftColorChanged,
|
||||
duration: settings.duration,
|
||||
onDurationChanged: _onDurationChanged);
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DirectSelectItem extends StatelessWidget {
|
||||
final String title;
|
||||
final bool isForList;
|
||||
|
||||
DirectSelectItem({this.title, this.isForList});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 60,
|
||||
child: isForList
|
||||
? Padding(
|
||||
child: _buildItem(context),
|
||||
padding: EdgeInsets.all(10),
|
||||
)
|
||||
: Card(
|
||||
margin: EdgeInsets.symmetric(horizontal: 10),
|
||||
child: Stack(
|
||||
children: [
|
||||
_buildItem(context),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Icon(Icons.arrow_drop_down),
|
||||
)
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
Container _buildItem(BuildContext context) {
|
||||
return Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
alignment: Alignment.center,
|
||||
child: Text(title),
|
||||
);
|
||||
}
|
||||
}
|
61
lib/widgets/home/tabs/settings/duration_settings_widget.dart
Normal file
61
lib/widgets/home/tabs/settings/duration_settings_widget.dart
Normal file
@ -0,0 +1,61 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_picker/flutter_picker.dart';
|
||||
|
||||
class DurationSettingsWidget extends StatelessWidget {
|
||||
final Duration duration;
|
||||
final void Function(Duration) updateDuration;
|
||||
|
||||
DurationSettingsWidget({
|
||||
@required this.duration,
|
||||
@required this.updateDuration,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
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: TextButton(
|
||||
onPressed: () {
|
||||
Picker(
|
||||
adapter: NumberPickerAdapter(
|
||||
data: [
|
||||
const NumberPickerColumn(
|
||||
begin: 0,
|
||||
end: 999,
|
||||
suffix: Text(" Y"),
|
||||
),
|
||||
const NumberPickerColumn(
|
||||
begin: 0,
|
||||
end: 11,
|
||||
suffix: Text(" M"),
|
||||
),
|
||||
const NumberPickerColumn(
|
||||
begin: 0,
|
||||
end: 30,
|
||||
suffix: Text(" D"),
|
||||
),
|
||||
],
|
||||
),
|
||||
hideHeader: true,
|
||||
confirmText: "OK",
|
||||
title: const Text("Select Duration"),
|
||||
selectedTextStyle: TextStyle(color: Colors.blue),
|
||||
onConfirm: (Picker picker, List<int> value) {
|
||||
int years = value[0], months = value[1], days = value[2];
|
||||
days = (years * 365) + (months * 30) + days;
|
||||
Duration newDuration = Duration(days: days);
|
||||
updateDuration(newDuration);
|
||||
},
|
||||
).showDialog(context);
|
||||
},
|
||||
child: Text("Default Duration: $years Y - $months M - $days D"),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user