PavelS0 / docx_template_dart

A Docx template engine
Apache License 2.0
40 stars 20 forks source link

style of the text in a list #10

Closed briceAlex closed 3 years ago

briceAlex commented 3 years ago

Hi, I have this list : Task:

I don't know how to have the bold side and the normal side text .

If you can help me please.

Thank you for your work !

PavelS0 commented 3 years ago

Hi, you can pass PlainContent instead of TextContent. And in PlainContent pass two TextContent's with different styles. Like this: image

Example code:

ListContent("listnested", [
    PlainContent("value")
      ..add(TextContent("normal", "BMW MTech"))
      ..add(TextContent("bold", "S55")),
    PlainContent("value")
      ..add(TextContent("normal", "BMW"))
      ..add(TextContent("bold", "N55")),
  ]

Result: image

briceAlex commented 3 years ago

Hi, Thank you for your answer, I understand, but I have a list of content like this :

`

            var listTaches = <Content>[];
            var listTachesCom = <Content>[];

            listTaches = afficheTache(db);
            listTachesCom = afficheTacheCom(db);

            c
              ..add(TextContent("docname", "Simple test"))
              ..add(ListContent("Taches",[
                TextContent("value", "Tâches :")
                ..add(ListContent("listnested", [
                  PlainContent("plain")
                    listTaches,
                  PlainContent("plain")
                    listTachesCom

                ])` 
PavelS0 commented 3 years ago

if I understood the problem correctly, in your example, one PlainContent contains only an array of text with a nomal style, and the second PlainContent contains only an array of text with a bold style.

Should be in one PlainContent both bold and normal style. The PlainContent will be the representation of the row in the list. Example:

final listNormal = ['Foo', 'Bar', 'Baz'];
final listBold = ['ooF', 'raB', 'zaB'];

final contentList = <Content>[];

final b = listBold.iterator;
for (var n in listNormal) {
  // iterate two arrays syncronously
  b.moveNext();
  // add both normal text and bold text to PlainContent
  final c = PlainContent("value")
    ..add(TextContent("normal", n))
    ..add(TextContent("bold", b.current));
  // add PlainContent to List
  contentList.add(c);
}
// pass list to ListContent
c..add(ListContent("listnested", contentList));
briceAlex commented 3 years ago

Yes, I have a database (Hive), and yes I would like to display a normal and bold text on the same line in a list.

I follow your idea, but I have an issue, nothing is displayed : listTag

the code : `

          var contentList = <Content>[];

          // db is the database, var db = tacheBox.values;

          for (Tache n in db){

              print(n.type+" = taches");
              if(n.type=="tâches"){
                final c = PlainContent("Plain")
                ..add(TextContent("titre",n.titre))
                ..add(TextContent("com",n.commentaire));       
                contentList.add(c); 
              }
            }
            c
              ..add(TextContent("docname", "Simple test"))
              ..add(ListContent("Taches",[
                TextContent("value", "tâche :")
                ..add(ListContent("listnested", contentList)
                )]));

` display : image

Thank you for your help.

PavelS0 commented 3 years ago

Tag names is case sensitive, so: final c = PlainContent("plain")

briceAlex commented 3 years ago

Ho, thank you !