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
47
lib/widgets/buttons/select_duration_btn.dart
Normal file
47
lib/widgets/buttons/select_duration_btn.dart
Normal file
@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_picker/flutter_picker.dart';
|
||||
|
||||
class SelectDurationBtn extends StatelessWidget {
|
||||
final Duration duration;
|
||||
final void Function(Duration) updateDuration;
|
||||
|
||||
SelectDurationBtn({
|
||||
@required this.duration,
|
||||
@required this.updateDuration,
|
||||
});
|
||||
|
||||
void _onPickerConfirm(Picker picker, List<int> values) {
|
||||
int years = values[0], months = values[1], days = values[2];
|
||||
days = (years * 365) + (months * 31) + days;
|
||||
Duration newDuration = Duration(days: days);
|
||||
updateDuration(newDuration);
|
||||
}
|
||||
|
||||
void _onButtonPressed(BuildContext context, ThemeData appTheme) => 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: 31, suffix: Text(" D")),
|
||||
]),
|
||||
hideHeader: false,
|
||||
title: const Text("Default Duration"),
|
||||
selectedTextStyle: TextStyle(color: appTheme.accentColor),
|
||||
onConfirm: _onPickerConfirm)
|
||||
.showModal(context);
|
||||
|
||||
@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);
|
||||
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,
|
||||
));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user