layout method

  1. @override
PwBox layout(
  1. Context context,
  2. BoxConstraints constraints
)
override

layout API.

Implementation

@override
PwBox layout(Context context, BoxConstraints constraints) {
  final List<PwHeading> source = context.frozenHeadings.isNotEmpty
      ? context.frozenHeadings
      : context.headings;
  final List<Widget> rows = <Widget>[
    Header(level: 1, text: title, title: title),
    const SizedBox(height: 6),
  ];
  for (final PwHeading heading in source) {
    if (heading.level < minLevel || heading.level > maxLevel) {
      continue;
    }
    if (heading.title == title) {
      continue;
    }
    final double indent = (heading.level - minLevel) * 14.0;
    final bool rtl = context.textDirection == TextDirection.rtl;
    final TextStyle linkStyle = TextStyle(
      fontSize: heading.level == 1 ? 11 : 10,
      color: '1565C0',
      decoration: TextDecoration.underline,
    );
    rows.add(
      Padding(
        padding: EdgeInsets.only(
          left: rtl ? 0 : indent,
          right: rtl ? indent : 0,
          bottom: 4,
        ),
        child: Link(
          destination: heading.title,
          child: Row(
            children: <Widget>[
              Expanded(child: Text(heading.title, style: linkStyle)),
              if (showPageNumbers)
                Text(
                  '${heading.pageNumber}',
                  style: const TextStyle(fontSize: 10, color: '546E7A'),
                ),
            ],
          ),
        ),
      ),
    );
  }
  return Column(children: rows).layout(context, constraints);
}