Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to create pdf like form layout in flutter?

I am wondering if I can make a text layout like this:

1

The colons are aligned with each other, and so are the values. I tried using a fixed-width container with space between rows as a child but the value part is not aligned, any idea guys?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Column(
 children: [
  Container(
   width: MediaQuery.of(context).size.width * .4
   child: Row(
    mainAxisAlignment: MainAxisAlignment.spaceBetween,
    children: [
     Text('Jenis Layanan'),
     Text(':')
    ]
   )
  )
 ]
)

>Solution :

Yes you can. I personally use Table for this case.

import 'package:flutter/material.dart';

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

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

  /// Table row widget
  TableRow buildTableRow(String title, String value) {
    return TableRow(
      children: [
        // This widget is for the value of first column
        Padding(
          padding: const EdgeInsets.fromLTRB(8, 4, 8, 4),
          child: Text(
            title,
          ),
        ),
        // This widget is for the value of second column
        Padding(
          padding: const EdgeInsets.all(4),
          child: Text(': $value'),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          // Creating table
          child: Table(
            // The [columnWidths] value must be equal with the total column of [buildTableRow]
            columnWidths: const {
              // Creates the first column width based on intrinsic sizing.
              // 
              // This [IntrinsicColumnWidth()] is expensive, so don't use it too often.
              0: IntrinsicColumnWidth(),
              // The second column take all the remaining space.
              1: FlexColumnWidth(),
            },
            // This is where to put the [TableRow]
            children: [
              buildTableRow('Jenis Layanan', 'Tarik Tunai'),
              buildTableRow('Bank Tujuan', 'BRI'),
              buildTableRow('No Rekening', '0129319201'),
              buildTableRow('Nama Pemilik Rekening', 'Adam'),
              buildTableRow('Nominal', 'Rp. 10.000'),
            ],
          ),
        ),
      ),
    );
  }
}

And this is the output:

Table Flutter

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading