Giter VIP home page Giter VIP logo

Comments (5)

ReinBentdal avatar ReinBentdal commented on May 18, 2024

I havent thought about that yet! I am always open for suggestions on how to do anything.

The implementation would be something like this:

Text.rich(TextSpan(children: [
  TextSpan(text: 'some text')
    .bold(),
  TextSpan(text: 'more text')
    .italic(),
])

I havent used TextSpan myself before so i am open to other suggestions.

I cannot guarantee that i actually will implement this feature eighter. At the moment i am developing the package by myself and my time is somewhat limited.
It is very easy to learn how the package works and to implement it by yourself if you want the feature, or want to contribute. I am very open for pull requests

from styled_widget.

fibbers avatar fibbers commented on May 18, 2024

Ok cool, I have experimented already a bit.

The Text widget has 2 (mutual exclusive) constructors which makes this a bit harder since extensions can't have constructors, so I tried some things using static methods to achieve a 'short' API:

extension StyledTextWithSpans on Text {
  static Text withSpans(List<TextSpan> children) => Text.rich(TextSpan(
        children: children,
      ));
}

extension StyledTextSpan on TextSpan {
  ...
}

StyledTextWithSpans.withSpans([
  TextSpan(text: 'Regular text, and '),
  TextSpan(text: 'bold text').textColor(Colors.green).bold(),
]),

However, I realise that the static utility method might not be suitable to be included in this library (maybe in the Flutter framework itself or just in my own code), so it indeed comes down to the API you suggested.

I'll see if I can make a PR out of just the TextSpan extension.

from styled_widget.

ReinBentdal avatar ReinBentdal commented on May 18, 2024

Its best to keep it as close to "native flutter" as possible and only changing whats really needed. With the example i gave above the only thing that has to be implemented is the styled methods for TextSpan. And these method would basicly be the same as the styled methods for Text. Eighter you could just copy most of the methods from the Text extension, or they could share the same methods by having a common mixin which both of them include. I dont think the last option is currently possible.

If you just use Text.rich() it would make it a bit easier i think. As i said, rely as much as possible on the flutter framework.

Looking forward to seeing what you come up with!

from styled_widget.

fibbers avatar fibbers commented on May 18, 2024

Thanks for helping out on this so quickly! 👍

from styled_widget.

ReinBentdal avatar ReinBentdal commented on May 18, 2024

#13 Feature implemented

from styled_widget.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.