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

ExtendedWidgetSpan does not scroll correctly when on the first line of a ExtendedTextField #130

Open
Zarainia opened this issue Jul 25, 2021 · 4 comments

Comments

@Zarainia
Copy link

When on the first line of the multiline ExtendedTextField, the ExtendedWidgetSpan seems to position itself incorrectly and moves up above the bounds of the textfield as more text is added below it.

Here, the same ExtendedWidgetSpan can be seen on the first line:
image

And on the second line:
image

(The light-coloured borders indicate the bounds of the ExtendedTextField.)

Platform is Windows desktop.

@Zarainia
Copy link
Author

Here is a simple example:

import 'package:extended_text_field/extended_text_field.dart';
import 'package:flutter/material.dart';

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

class MySpecialTextSpanBuilder extends SpecialTextSpanBuilder {
  MySpecialTextSpanBuilder();

  @override
  TextSpan build(String data, {TextStyle? textStyle, onTap}) {
    return SpecialTextSpan(
      text: '',
      actualText: '',
      children: [
        SpecialTextSpan(text: '\n', actualText: ''),
        ExtendedWidgetSpan(
          child: Container(
            height: 1000,
            color: Colors.red,
          ),
          actualText: '',
        )
      ],
    );
  }

  @override
  SpecialText? createSpecialText(String flag, {TextStyle? textStyle, SpecialTextGestureTapCallback? onTap, required int index}) {}
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          // Here we take the value from the MyHomePage object that was created by
          // the App.build method, and use it to set our appbar title.
          title: Text("Test"),
        ),
        body: Column(
          children: [
            Expanded(
                child: Container(
              color: Colors.blue,
            )),
            Expanded(
                child: ExtendedTextField(
              minLines: null,
              maxLines: null,
              expands: true,
              textAlignVertical: TextAlignVertical.top,
              keyboardType: TextInputType.multiline,
              specialTextSpanBuilder: MySpecialTextSpanBuilder(),
            ))
          ],
        ), // This trailing comma makes auto-formatting nicer for build methods.
      ),
    );
  }
}

You will see that if you comment out the SpecialTextSpan containing a newline, the red ExtendedWidgetSpan box moves to be above the textfield.

@zmtzawqlp
Copy link
Member

try latest version

@Zarainia
Copy link
Author

Zarainia commented Jan 1, 2022

Still happens:
image

@zmtzawqlp
Copy link
Member

please release an issue for flutter team

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          // Here we take the value from the MyHomePage object that was created by
          // the App.build method, and use it to set our appbar title.
          title: Text("Test"),
        ),
        body: Column(
          children: [
            Expanded(
                child: Container(
              color: Colors.blue,
            )),
            Expanded(
                child:
                    // Extended
                    TextField(
              minLines: null,
              maxLines: null,
              expands: true,
              textAlignVertical: TextAlignVertical.top,
              keyboardType: TextInputType.multiline,
              controller: MyTextEditingController(),
              //specialTextSpanBuilder: MySpecialTextSpanBuilder(),
            ))
          ],
        ), // This trailing comma makes auto-formatting nicer for build methods.
      ),
    );
  }
}

class MyTextEditingController extends TextEditingController {
  @override
  TextSpan buildTextSpan(
      {required BuildContext context,
      TextStyle? style,
      required bool withComposing}) {
    return TextSpan(
      children: [
        // TextSpan(text: '1'),
        WidgetSpan(
          child: Container(
            height: 1000,
            color: Colors.red,
          ),
        )
      ],
    );
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants