0

i have code like this

return DefaultTabController(
  length: 4,
  child: Scaffold(
      appBar: AppBar(
        title: Text("Halaman Dashboard"),
        actions: <Widget>[
          IconButton(
            onPressed: () {
              signOut();
            },
            icon: Icon(Icons.lock_open),
          )
        ],
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RaisedButton(
              child: Text('Scan'),
              onPressed: () async {
                try {
                  String barcode = await BarcodeScanner.scan();
                  setState(() {
                    this.barcode = barcode;
                  });
                } on PlatformException catch (error) {
                  if (error.code == BarcodeScanner.CameraAccessDenied) {
                    setState(() {
                      this.barcode =
                          'Izin kamera tidak diizinkan oleh si pengguna';
                    });
                  } else {
                    setState(() {
                      this.barcode = 'Error: $error';
                    });
                  }
                }
              },
            ),
            Text(
              'Result: $barcode', //THIS 
              textAlign: TextAlign.center,
            ),
          ],
        ),
      )),
);

variable $barcode with comment //THIS has a value like "abc; def; ghi; ..", the value is displayed in one line, how do I display the value in a list like

Name: Abc

addres: def

phone: ghi ?

1 Answers1

0

Use Split.

for more details https://stackoverflow.com/a/55358328/11794336

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  static const String example = 'abc; def; ghi;';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: ListView(
          children: example
              .split(';')                       // split the text into an array
              .map((String text) => Text(text)) // put the text inside a widget
              .toList(),                        // convert the iterable to a list
        )
      ),
    );
  }
}
Naeem
  • 494
  • 1
  • 7
  • 25