Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix opening keyboard when selecting event/exam time #1790

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,42 +60,55 @@ Future<void> _showUserConfirmationOfEventArrival({
/// Not using final will cause the linter to complain about the lint below, so
/// we have to ignore it.
// ignore: must_be_immutable
class TimetableAddEventDialog extends StatelessWidget {
class TimetableAddEventDialog extends StatefulWidget {
TimetableAddEventDialog({
super.key,
required this.isExam,
@visibleForTesting this.controller,
@visibleForTesting TimeOfDay Function()? showTimePickerTestOverride,
@visibleForTesting FocusNode? titleFocusNode,
@visibleForTesting this.titleFocusNode,
}) {
this.titleFocusNode = titleFocusNode ?? FocusNode();
_timePickerOverride = showTimePickerTestOverride;
}

final bool isExam;
late AddEventDialogController? controller;
late final FocusNode titleFocusNode;
bool _hasRequestedTitleFocus = false;

late final FocusNode? titleFocusNode;
static const tag = "timetable-event-dialog";

@override
State<TimetableAddEventDialog> createState() =>
_TimetableAddEventDialogState();
}

class _TimetableAddEventDialogState extends State<TimetableAddEventDialog> {
late AddEventDialogController controller;
late FocusNode titleFocusNode;

@override
void initState() {
super.initState();
titleFocusNode = widget.titleFocusNode ?? FocusNode();
controller = widget.controller ??
AddEventDialogController(
isExam: widget.isExam,
api: EventDialogApi(BlocProvider.of<SharezoneContext>(context).api),
markdownAnalytics: BlocProvider.of<MarkdownAnalytics>(context),
);

WidgetsBinding.instance.addPostFrameCallback((_) {
delayKeyboard(context: context, focusNode: titleFocusNode);
});
}

bool hasModifiedData() {
return controller!.title.isNotEmpty || controller!.description.isNotEmpty;
return controller.title.isNotEmpty || controller.description.isNotEmpty;
}

@override
Widget build(BuildContext context) {
if (!_hasRequestedTitleFocus) {
_hasRequestedTitleFocus = true;
delayKeyboard(context: context, focusNode: titleFocusNode);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jonas-Sander Do you know if there was a reason why you called the delayKeyboard in the build() method instead of using a StatefulWidget with initState?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, probably just laziness.

}
controller ??= AddEventDialogController(
isExam: isExam,
api: EventDialogApi(BlocProvider.of<SharezoneContext>(context).api),
markdownAnalytics: BlocProvider.of<MarkdownAnalytics>(context),
);
return ChangeNotifierProvider(
create: (context) => controller,
return ChangeNotifierProvider.value(
value: controller,
builder: (context, __) => PopScope<Object?>(
canPop: false,
onPopInvokedWithResult: (didPop, _) async {
Expand All @@ -118,11 +131,11 @@ class TimetableAddEventDialog extends StatelessWidget {
children: <Widget>[
_AppBar(
editMode: false,
isExam: isExam,
isExam: widget.isExam,
titleField: _TitleField(
key: EventDialogKeys.titleTextField,
focusNode: titleFocusNode,
isExam: isExam,
isExam: widget.isExam,
)),
Expanded(
child: SingleChildScrollView(
Expand All @@ -134,11 +147,11 @@ class TimetableAddEventDialog extends StatelessWidget {
const _MobileDivider(),
const _DateAndTimePicker(),
const _MobileDivider(),
_DescriptionField(isExam: isExam),
_DescriptionField(isExam: widget.isExam),
const _MobileDivider(),
const _Location(),
const _MobileDivider(),
_SendNotification(isExam: isExam),
_SendNotification(isExam: widget.isExam),
],
),
),
Expand Down
Loading