Skip to content

Commit

Permalink
Fix notes not opening
Browse files Browse the repository at this point in the history
Move clear button inside the text field
  • Loading branch information
evgfilim1 committed Apr 11, 2024
1 parent 7454fd9 commit 2879b4c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
9 changes: 8 additions & 1 deletion lib/screens/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ class MainScreen extends StatefulWidget {

class _MainScreenState extends State<MainScreen> {
var _showRoles = false;
final _notes = TextEditingController();

@override
void initState() {
unawaited(_checkForUpdates());
super.initState();
}

@override
void dispose() {
_notes.dispose();
super.dispose();
}

Future<void> _checkForUpdates() async {
if (kIsWeb || isDev) {
return;
Expand Down Expand Up @@ -117,7 +124,7 @@ class _MainScreenState extends State<MainScreen> {
onPressed: () => Navigator.pushNamed(context, "/log"),
child: const Text("Журнал игры"),
),
const NotesMenuItemButton(),
NotesMenuItemButton(context: context, controller: _notes),
CheckboxMenuButton(
value: _showRoles,
onChanged: (value) => setState(() => _showRoles = value ?? false),
Expand Down
47 changes: 22 additions & 25 deletions lib/widgets/notes_menu_item_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,40 @@ import "package:flutter/material.dart";

import "../utils/ui.dart";

class NotesMenuItemButton extends StatefulWidget {
const NotesMenuItemButton({super.key});
class NotesMenuItemButton extends StatelessWidget {
final BuildContext context;
final TextEditingController controller;

@override
State<NotesMenuItemButton> createState() => _NotesMenuItemButtonState();
}

class _NotesMenuItemButtonState extends State<NotesMenuItemButton> {
final _notesController = TextEditingController();

@override
void dispose() {
_notesController.dispose();
super.dispose();
}
const NotesMenuItemButton({
super.key,
required this.context,
required this.controller,
});

void _showNotes(BuildContext context) {
showSimpleDialog(
context: context,
title: const Text("Заметки"),
content: TextField(
controller: _notesController,
controller: controller,
maxLines: null,
),
extraActions: [
TextButton(
onPressed: _notesController.clear,
child: const Text("Очистить"),
decoration: InputDecoration(
suffixIcon: IconButton(
icon: const Icon(Icons.clear),
onPressed: controller.clear,
),
suffixIconColor: Colors.grey,
),
],
textCapitalization: TextCapitalization.sentences,
autofocus: true,
),
);
}

@override
Widget build(BuildContext context) => MenuItemButton(
leadingIcon: const Icon(Icons.sticky_note_2, size: Checkbox.width),
onPressed: () => _showNotes(context),
child: const Text("Заметки"),
);
leadingIcon: const Icon(Icons.sticky_note_2, size: Checkbox.width),
onPressed: () => _showNotes(this.context),
child: const Text("Заметки"),
);
}

0 comments on commit 2879b4c

Please sign in to comment.