Skip to content

Commit

Permalink
Made NT4 widget child a non-nullable type
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Dec 6, 2023
1 parent 728a12e commit 8098133
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 37 deletions.
18 changes: 8 additions & 10 deletions lib/widgets/dashboard_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,11 @@ class DashboardGrid extends StatelessWidget {
} else if (!isValidLocation(previewLocation)) {
_containerDraggingIn = null;

if (widget.child is NT4Widget) {
widget.child?.dispose(deleting: !fromLayout);
if (!fromLayout) {
widget.child?.unSubscribe();
}
widget.child.dispose(deleting: !fromLayout);
if (!fromLayout) {
widget.child.unSubscribe();
}

refresh();
return;
} else {
Expand All @@ -519,7 +517,7 @@ class DashboardGrid extends StatelessWidget {

_containerDraggingIn = null;

widget.child?.dispose();
widget.child.dispose();

refresh();
}
Expand Down Expand Up @@ -586,10 +584,10 @@ class DashboardGrid extends StatelessWidget {
for (DraggableNT4WidgetContainer container
in _widgetContainers.whereType<DraggableNT4WidgetContainer>()) {
String? title = container.title;
String? type = container.child?.type;
String? topic = container.child?.topic;
String? type = container.child.type;
String? topic = container.child.topic;

if (title == null || type == null || topic == null) {
if (title == null) {
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/widgets/draggable_containers/draggable_list_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class DraggableListLayout extends DraggableLayoutContainer {
child: ExpansionTile(
title: Text(container.title ?? ''),
subtitle: Text(
container.child?.type ?? 'NT4Widget'),
container.child.type ?? 'NT4Widget'),
controlAffinity:
ListTileControlAffinity.leading,
trailing: IconButton(
Expand Down Expand Up @@ -202,7 +202,7 @@ class DraggableListLayout extends DraggableLayoutContainer {
];

List<Widget> childEditProperties =
container.child!.getEditProperties(context);
container.child.getEditProperties(context);

return [
...containerEditProperties,
Expand Down Expand Up @@ -335,7 +335,7 @@ class DraggableListLayout extends DraggableLayoutContainer {
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 1.5, vertical: 2.0),
child: widget.child!,
child: widget.child,
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '../dialog_widgets/dialog_text_input.dart';
import '../nt4_widgets/nt4_widget.dart';

class DraggableNT4WidgetContainer extends DraggableWidgetContainer {
NT4Widget? child;
late NT4Widget child;

DraggableNT4WidgetContainer({
super.key,
Expand Down Expand Up @@ -55,7 +55,7 @@ class DraggableNT4WidgetContainer extends DraggableWidgetContainer {
Map<String, dynamic> toJson() {
return {
...super.toJson(),
'type': child?.type,
'type': child.type,
'properties': getChildJson(),
};
}
Expand Down Expand Up @@ -86,48 +86,48 @@ class DraggableNT4WidgetContainer extends DraggableWidgetContainer {
}

void refreshChild() {
child?.refresh();
child.refresh();
}

@override
void dispose({bool deleting = false}) {
super.dispose(deleting: deleting);

child?.dispose(deleting: deleting);
child.dispose(deleting: deleting);
}

@override
void unSubscribe() {
super.unSubscribe();

child?.unSubscribe();
child.unSubscribe();
}

Map<String, dynamic>? getChildJson() {
return child!.toJson();
return child.toJson();
}

void changeChildToType(String? type) {
if (type == null) {
return;
}

if (type == child!.type) {
if (type == child.type) {
return;
}

NT4Widget? newWidget = NT4WidgetBuilder.buildNT4WidgetFromType(
type,
child!.type,
period: child!.period,
child.type,
period: child.period,
);

if (newWidget == null) {
return;
}

child!.dispose(deleting: true);
child!.unSubscribe();
child.dispose(deleting: true);
child.unSubscribe();
child = newWidget;

minWidth = NT4WidgetBuilder.getMinimumWidth(child);
Expand All @@ -149,7 +149,7 @@ class DraggableNT4WidgetContainer extends DraggableWidgetContainer {
child: StatefulBuilder(
builder: (context, setState) {
List<Widget>? childProperties =
child?.getEditProperties(context);
child.getEditProperties(context);
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -163,8 +163,8 @@ class DraggableNT4WidgetContainer extends DraggableWidgetContainer {
children: [
const Center(child: Text('Widget Type')),
DialogDropdownChooser<String>(
choices: child!.getAvailableDisplayTypes(),
initialValue: child!.type,
choices: child.getAvailableDisplayTypes(),
initialValue: child.type,
onSelectionChanged: (String? value) {
setState(() {
changeChildToType(value);
Expand All @@ -175,9 +175,8 @@ class DraggableNT4WidgetContainer extends DraggableWidgetContainer {
),
const Divider(),
// Settings for the widget inside (only if there are properties)
if (childProperties != null &&
childProperties.isNotEmpty) ...[
Text('${child?.type} Widget Settings'),
if (childProperties.isNotEmpty) ...[
Text('${child.type} Widget Settings'),
const SizedBox(height: 5),
...childProperties,
const Divider(),
Expand All @@ -194,7 +193,7 @@ class DraggableNT4WidgetContainer extends DraggableWidgetContainer {
TextButton(
onPressed: () {
Navigator.of(context).pop();
child?.refresh();
child.refresh();
},
child: const Text('Close'),
),
Expand All @@ -216,11 +215,11 @@ class DraggableNT4WidgetContainer extends DraggableWidgetContainer {
Flexible(
child: DialogTextInput(
onSubmit: (value) {
child?.topic = value;
child?.resetSubscription();
child.topic = value;
child.resetSubscription();
},
label: 'Topic',
initialText: child?.topic,
initialText: child.topic,
),
),
const SizedBox(width: 5),
Expand All @@ -233,12 +232,12 @@ class DraggableNT4WidgetContainer extends DraggableWidgetContainer {
return;
}

child!.period = newPeriod;
child!.resetSubscription();
child.period = newPeriod;
child.resetSubscription();
},
formatter: FilteringTextInputFormatter.allow(RegExp(r"[0-9.]")),
label: 'Period',
initialText: child!.period.toString(),
initialText: child.period.toString(),
),
),
],
Expand Down

0 comments on commit 8098133

Please sign in to comment.