Answer the question
In order to leave comments, you need to log in
Why is the widget being rebuilt multiple times when passing arguments through the Navigator?
This is the code with the table:
import 'package:flutter/material.dart';
import 'package:csv/csv.dart';
import 'dart:io';
class ShowTable extends StatefulWidget {
@override
_ShowTableState createState() => _ShowTableState();
}
class _ShowTableState extends State<ShowTable> {
List<List<dynamic>> data = [];
void _load() async {
// String linkOfDict = ModalRoute.of(context).settings.arguments;
String linkOfDict =
'/data/data/com.example.eng_translator/app_flutter/sales.csv';
String contents = await File(linkOfDict).readAsString();
data = CsvToListConverter().convert(contents);
setState(() {});
print(data);
}
@override
void initState() {
super.initState();
_load();
}
@override
Widget build(BuildContext context) {
// _load();
return Scaffold(
appBar: AppBar(
title: Text("Table"),
),
body: SingleChildScrollView(
child: Table(
columnWidths: {
0: FlexColumnWidth(1),
},
border: TableBorder.all(width: 1.0),
children: data.map((item) {
return TableRow(
children: item.map((row) {
return Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
row.toString(),
style: TextStyle(fontSize: 20.0),
),
),
);
}).toList());
}).toList(),
),
),
);
}
}
Navigator.pushNamed(context, '/show_table', arguments: linkOfDict);
Answer the question
In order to leave comments, you need to log in
setState causes the widget to be redrawn, respectively, Widget build(BuildContext context) is called, in which you call the redraw again
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question