Updated Flutter SDK for Null-Safety
Ported Progress Detail Screen to PlatformScaffold Signed-off-by: Andreas Fahrecker <AndreasFahrecker@gmail.com>
This commit is contained in:
@ -44,7 +44,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget _renderCreateProgressBtn() => _tabSelectedIndex == 2
|
||||
PlatformActionButton? _renderCreateProgressBtn() => _tabSelectedIndex == 2
|
||||
? null
|
||||
: PlatformActionButton(
|
||||
heroTag: "goToCreateTimeProgressBTN",
|
||||
|
@ -26,11 +26,11 @@ class ProgressCreationScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ProgressCreationScreenState extends State<ProgressCreationScreen> {
|
||||
TimeProgress timeProgressToCreate;
|
||||
TimeProgress timeProgressToCreate = TimeProgress.initialDefault();
|
||||
bool _isProgressValid = false;
|
||||
|
||||
void initTimeProgress(TimeProgress timeProgress) {
|
||||
if (timeProgressToCreate == null)
|
||||
if (timeProgressToCreate == TimeProgress.initialDefault())
|
||||
setState(() {
|
||||
timeProgressToCreate = timeProgress;
|
||||
});
|
||||
@ -180,8 +180,8 @@ 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) {
|
||||
|
@ -1,18 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
import 'package:time_progress_tracker/models/time_progress.dart';
|
||||
import 'package:time_progress_tracker/redux/store_connectors/settings_store_connector.dart';
|
||||
import 'package:time_progress_tracker/redux/store_connectors/time_progress_store_connector.dart';
|
||||
import 'package:time_progress_tracker/ui/screens/dashboard_screen.dart';
|
||||
import 'package:time_progress_tracker/ui/detail_screen_floating_action_buttons.dart';
|
||||
import 'package:time_progress_tracker/ui/buttons/detail_screen_leading_button.dart';
|
||||
import 'package:time_progress_tracker/ui/buttons/detail_screen_trailing_button.dart';
|
||||
import 'package:time_progress_tracker/ui/progress/progress_editor_widget.dart';
|
||||
import 'package:time_progress_tracker/ui/progress/progress_view_widget.dart';
|
||||
import 'package:time_progress_tracker/utils/theme_utils.dart';
|
||||
|
||||
class ProgressDetailScreen extends StatefulWidget {
|
||||
static const title = "Progress View";
|
||||
|
||||
final String tpId;
|
||||
|
||||
const ProgressDetailScreen({Key key, @required this.tpId}) : super(key: key);
|
||||
const ProgressDetailScreen({Key? key, required this.tpId}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
@ -22,10 +24,11 @@ class ProgressDetailScreen extends StatefulWidget {
|
||||
|
||||
class _ProgressDetailScreenState extends State<ProgressDetailScreen> {
|
||||
bool _editMode = false, _isEditedProgressValid = false;
|
||||
TimeProgress _editedProgress, _originalProgress;
|
||||
TimeProgress _editedProgress = TimeProgress.initialDefault(),
|
||||
_originalProgress = TimeProgress.initialDefault();
|
||||
|
||||
void _initEditedProgress(TimeProgress tp) {
|
||||
if (_editedProgress == null) {
|
||||
if (_editedProgress == TimeProgress.initialDefault()) {
|
||||
_editedProgress = tp;
|
||||
_originalProgress = tp;
|
||||
}
|
||||
@ -54,10 +57,11 @@ class _ProgressDetailScreenState extends State<ProgressDetailScreen> {
|
||||
|
||||
List<Widget> _renderColumnChildren(
|
||||
SettingsViewModel settingsVm, TimeProgressViewModel tpVm) {
|
||||
TimeProgress tp = tpVm.tp ?? TimeProgress.initialDefault();
|
||||
List<Widget> columnChildren = [
|
||||
Expanded(
|
||||
child: ProgressViewWidget(
|
||||
timeProgress: _editMode ? _editedProgress : tpVm.tp,
|
||||
timeProgress: _editMode ? _editedProgress : tp,
|
||||
doneColor: settingsVm.appSettings.doneColor,
|
||||
leftColor: settingsVm.appSettings.leftColor,
|
||||
))
|
||||
@ -73,16 +77,67 @@ class _ProgressDetailScreenState extends State<ProgressDetailScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(ProgressDetailScreen.title),
|
||||
TimeProgressStoreConnector leadingActionButton = TimeProgressStoreConnector(
|
||||
timeProgressId: widget.tpId,
|
||||
loadedBuilder: (context, tpVm) {
|
||||
void _saveEditedTp() {
|
||||
tpVm.updateTimeProgress(_editedProgress);
|
||||
_switchEditMode(false);
|
||||
}
|
||||
|
||||
return DetailScreenLeadingButton(
|
||||
isEditMode: _editMode,
|
||||
isEditedTpValid: _isEditedProgressValid,
|
||||
saveTp: _saveEditedTp,
|
||||
editTp: () => _switchEditMode(true),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
TimeProgressStoreConnector trailingActionButton =
|
||||
TimeProgressStoreConnector(
|
||||
timeProgressId: widget.tpId,
|
||||
loadedBuilder: (context, tpVm) {
|
||||
void _deleteTp() {
|
||||
tpVm.deleteTimeProgress();
|
||||
Navigator.popUntil(context, (route) => route.isFirst);
|
||||
}
|
||||
|
||||
return DetailScreenTrailingButton(
|
||||
isEditMode: _editMode,
|
||||
cancelEditTp: _cancelEditMode,
|
||||
deleteTp: _deleteTp,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
return PlatformScaffold(
|
||||
appBar: PlatformAppBar(
|
||||
title: Text(
|
||||
ProgressDetailScreen.title,
|
||||
style: toolbarTextStyle,
|
||||
),
|
||||
cupertino: (_, __) => CupertinoNavigationBarData(
|
||||
transitionBetweenRoutes: false,
|
||||
leading: leadingActionButton,
|
||||
trailing: trailingActionButton,
|
||||
),
|
||||
),
|
||||
material: (_, __) => MaterialScaffoldData(
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
||||
floatingActionButton: Row(
|
||||
children: [
|
||||
Expanded(child: leadingActionButton),
|
||||
Expanded(child: trailingActionButton),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: SettingsStoreConnector(
|
||||
loadedBuilder: (context, settingsVm) {
|
||||
return TimeProgressStoreConnector(
|
||||
timeProgressId: widget.tpId,
|
||||
loadedBuilder: (context, tpVm) {
|
||||
_initEditedProgress(tpVm.tp);
|
||||
_initEditedProgress(tpVm.tp!);
|
||||
return Container(
|
||||
margin: EdgeInsets.all(8),
|
||||
child: Column(
|
||||
@ -92,32 +147,6 @@ class _ProgressDetailScreenState extends State<ProgressDetailScreen> {
|
||||
);
|
||||
},
|
||||
),
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
||||
floatingActionButton: TimeProgressStoreConnector(
|
||||
timeProgressId: widget.tpId,
|
||||
loadedBuilder: (context, tpVm) {
|
||||
void _saveEditedProgress() {
|
||||
tpVm.updateTimeProgress(_editedProgress);
|
||||
_switchEditMode(false);
|
||||
}
|
||||
|
||||
void _deleteTimeProgress() {
|
||||
tpVm.deleteTimeProgress();
|
||||
Navigator.popUntil(
|
||||
context, ModalRoute.withName(DashboardScreen.routeName));
|
||||
}
|
||||
|
||||
return DetailScreenFloatingActionButtons(
|
||||
editMode: _editMode,
|
||||
originalProgress: tpVm.tp,
|
||||
editedProgress: _editedProgress,
|
||||
isEditedProgressValid: _isEditedProgressValid,
|
||||
onEditProgress: () => _switchEditMode(true),
|
||||
onSaveEditedProgress: _saveEditedProgress,
|
||||
onCancelEditProgress: _cancelEditMode,
|
||||
onDeleteProgress: _deleteTimeProgress);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user