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

[BUG] Text Focus Problem (Flutter Web App) #538

Open
chrisDK1977 opened this issue Sep 23, 2024 · 3 comments
Open

[BUG] Text Focus Problem (Flutter Web App) #538

chrisDK1977 opened this issue Sep 23, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@chrisDK1977
Copy link

chrisDK1977 commented Sep 23, 2024

When using a TextInput and the html-editor-enhanced once the Textinput has got focus you cannot type anything in the HTML-editor anymore and the TextInput will always get the focus.

When clicking on the bold icon or somehting else in the editor toolbar and than in the text-input-area it works.

SampleApp:

import 'package:flutter/material.dart';
import 'package:html_editor_enhanced/html_editor.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late final TextEditingController textController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Row(
                children: [
                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.all(5.0),
                      child: TextField(
                        controller: textController,
                        style: const TextStyle(fontWeight: FontWeight.bold),
                        onChanged: (val) => print(val), 
                      ),
                    ),
                  ),
                ],
              ),
              Expanded(
                child: HtmlEditor(controller: HtmlEditorController()),
              ),
            ]
        ),
      ),
    );
  }
}
@chrisDK1977 chrisDK1977 added the bug Something isn't working label Sep 23, 2024
@chrisDK1977 chrisDK1977 changed the title [BUG] [BUG] Text Focus Problem Sep 23, 2024
@chrisDK1977 chrisDK1977 changed the title [BUG] Text Focus Problem [BUG] Text Focus Problem (Flutter Web App) Sep 23, 2024
@chrisDK1977
Copy link
Author

adding

onFocus: () {
// Clear focus from other widgets
FocusScope.of(context).requestFocus(FocusNode());
// Set focus back to the HtmlEditor
_controller.setFocus();
}

seems to make it better - after switching many times sometimes I cannont get the focus back on the textfield... but it is not happening always...

are ther any other tricks to solve the problem?

@hptigger
Copy link

Experiencing the same issue.

@hptigger
Copy link

Adding the onFocus callback as noted has sorted things out for me 👍
Thank you @chrisDK1977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants