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
46
lib/widgets/buttons/color_picker_btn.dart
Normal file
46
lib/widgets/buttons/color_picker_btn.dart
Normal file
@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
||||
import 'package:time_progress_tracker/helper_functions.dart';
|
||||
|
||||
class ColorPickerButton extends StatelessWidget {
|
||||
final String title, dialogTitle;
|
||||
final Color selectedColor;
|
||||
final void Function(Color) onColorPicked;
|
||||
|
||||
ColorPickerButton({
|
||||
@required this.title,
|
||||
@required this.dialogTitle,
|
||||
@required this.selectedColor,
|
||||
@required this.onColorPicked,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ThemeData appTheme = Theme.of(context);
|
||||
return TextButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(dialogTitle),
|
||||
content: SingleChildScrollView(
|
||||
child: BlockPicker(
|
||||
pickerColor: selectedColor,
|
||||
onColorChanged: onColorPicked,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
child: Text(title),
|
||||
style: TextButton.styleFrom(
|
||||
primary: useBrightBackground(selectedColor)
|
||||
? appTheme.primaryTextTheme.button.color
|
||||
: appTheme.textTheme.button.color,
|
||||
backgroundColor: selectedColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
18
lib/widgets/buttons/create_progress_button.dart
Normal file
18
lib/widgets/buttons/create_progress_button.dart
Normal file
@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:time_progress_tracker/screens/progress_creation_screen.dart';
|
||||
|
||||
class CreateProgressButton extends StatelessWidget {
|
||||
final String _heroTag = "createProgressBTN";
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
void _onButtonPressed() =>
|
||||
Navigator.pushNamed(context, ProgressCreationScreen.routeName);
|
||||
|
||||
return FloatingActionButton(
|
||||
heroTag: _heroTag,
|
||||
child: Icon(Icons.add),
|
||||
onPressed: _onButtonPressed,
|
||||
);
|
||||
}
|
||||
}
|
36
lib/widgets/buttons/date_picker_btn.dart
Normal file
36
lib/widgets/buttons/date_picker_btn.dart
Normal file
@ -0,0 +1,36 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DatePickerBtn extends StatelessWidget {
|
||||
final String leadingString;
|
||||
final DateTime pickedDate;
|
||||
final void Function(DateTime) onDatePicked;
|
||||
|
||||
DatePickerBtn({
|
||||
@required this.leadingString,
|
||||
@required this.pickedDate,
|
||||
@required this.onDatePicked,
|
||||
}) : super();
|
||||
|
||||
void _onButtonPressed(BuildContext context) async {
|
||||
onDatePicked(await showDatePicker(
|
||||
context: context,
|
||||
initialDate: pickedDate,
|
||||
firstDate: DateTime(1900),
|
||||
lastDate: DateTime(2100),
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ThemeData appTheme = Theme.of(context);
|
||||
return TextButton(
|
||||
onPressed: () => _onButtonPressed(context),
|
||||
child: Text(
|
||||
"$leadingString ${pickedDate.toLocal().toString().split(" ")[0]}"),
|
||||
style: TextButton.styleFrom(
|
||||
primary: appTheme.primaryTextTheme.button.color,
|
||||
backgroundColor: appTheme.accentColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
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