How to convert from Map<String, dynamic> to List<String> in flutter - flutter

I'm trying to make multiple select widgets and the data from firebase database
CollectionReference submission = FirebaseFirestore.instance.collection('cuti'); is data with type Map<String, dynamic> while on dataSource: must be type List<object?>
this is the full code
class multiple extends StatefulWidget {
const multiple({super.key});
#override
State<multiple> createState() => _multipleState();
}
class _multipleState extends State<multiple> {
late MultiselectController _multiselectController;
late Random random;
late List<String> _items;
CollectionReference submission = FirebaseFirestore.instance.collection('cuti');
#override
void initState() {
super.initState();
_multiselectController = MultiselectController();
_items = List.generate(10, (index) => '$submission'); // in submission Type: Map<String, dynamic>
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('List'),
),
body: MultiselectScope(
controller: _multiselectController,
dataSource: _items, // in here must be Type: List<String>
clearSelectionOnPop: true,
keepSelectedItemsBetweenUpdates: true,
// initialSelectedIndexes: [1, 3],
onSelectionChanged: (selectedIndexes, selectedItems) {},
child: Padding(
padding: EdgeInsets.all(10),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: ListView.builder(
itemCount: _items.length,
itemBuilder: (context, index) {
final controller = MultiselectScope.controllerOf(context);
final itemSelected = controller.isSelected(index);
return InkWell(
onLongPress: () {
if (!controller.selectionAttached) {
controller.select(index);
}
},
onTap: () {
print('item is selected $itemSelected');
if (controller.selectionAttached) {
controller.select(index);
}
},
child: Padding(
padding: EdgeInsets.all(10),
child: Container(
color: itemSelected
? Theme.of(context).primaryColor
: null,
child: Text(
_items[index],
style: TextStyle(fontSize: 20),
),
),
),
);
},
),
)
],
),
),
),
);
}
}

Related

How to get the List of Strings from Shared Preferences without the Brackets

I want to save a List of Strings and display them in a ListView.builder Widget. The problem is when I get the value from the List I receive it with brackets around the value but I only need the String itself
Right now I'm getting: [value]
But I need to get: value
Here is my code:
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class PrefListViewBuilder extends StatefulWidget {
const PrefListViewBuilder({Key? key}) : super(key: key);
#override
State<PrefListViewBuilder> createState() => _PrefListViewBuilderState();
}
class _PrefListViewBuilderState extends State<PrefListViewBuilder> {
List stringList = [];
setStringList() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setStringList("key", <String>["value"]);
setState(() {
stringList.add(prefs.getStringList("key"));
});
print(stringList);
}
getStringList() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.getStringList("kfzs");
print(stringList);
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
onPressed: setStringList,
child: const Text("Set"),
),
TextButton(
onPressed: getStringList,
child: const Text("Get"),
),
],
),
const SizedBox(height: 20),
Text(stringList.toString()),
const SizedBox(height: 20),
Container(
color: Colors.white,
child: ListView.builder(
shrinkWrap: true,
itemCount: stringList.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(10),
child: Container(
color: Colors.blue,
child: Text(stringList[index].toString()),
),
);
},
),
),
],
),
);
}
}
Does anyone can help me with this?
Thanks in advance!
The getList will be
stringList = prefs.getStringList("key") ?? [];
instead of
stringList.add(prefs.getStringList("key"));
Full snippet
class PrefListViewBuilder extends StatefulWidget {
const PrefListViewBuilder({Key? key}) : super(key: key);
#override
State<PrefListViewBuilder> createState() => _PrefListViewBuilderState();
}
class _PrefListViewBuilderState extends State<PrefListViewBuilder> {
List stringList = [];
setStringList() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setStringList("key", <String>["value"]);
await getStringList();
setState(() {
// stringList = prefs.getStringList("key") ?? [];
});
print(stringList);
}
getStringList() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
stringList = prefs.getStringList("key") ?? [];
setState(() {});
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
onPressed: setStringList,
child: const Text("Set"),
),
TextButton(
onPressed: getStringList,
child: const Text("Get"),
),
],
),
const SizedBox(height: 20),
Text(stringList.toString()),
const SizedBox(height: 20),
Container(
color: Colors.white,
child: ListView.builder(
shrinkWrap: true,
itemCount: stringList.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(10),
child: Container(
color: Colors.blue,
child: Text(stringList[index]),
),
);
},
),
),
],
),
);
}
}

Flutter - Provider - Clearing Data itself when navigate

When I in a page and added some quantity and navigate to another page and come back to added more quantity data is cleared.
Here's my code.
add_inv_stream.dart
class AddInvStream extends StatelessWidget {
const AddInvStream({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
FirebaseServices services = FirebaseServices();
final provider = Provider.of<InventoryProvider>(context);
return StreamBuilder<QuerySnapshot>(
stream: services.inventory
.where('fishType', isEqualTo: provider.inventoryData['fishType'])
.where('status', isEqualTo: true)
.snapshots(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return const Center(child: Text('Something wrong!'));
}
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.data!.size == 0) {
return const Center(
child: Text('No inventories'),
);
}
return AddInvData(snapshot: snapshot, services: services);
},
);
}
}
add_inv_data.dart
class AddInvData extends StatefulWidget {
final AsyncSnapshot<QuerySnapshot<Object?>> snapshot;
final FirebaseServices services;
const AddInvData({Key? key, required this.snapshot, required this.services})
: super(key: key);
#override
State<AddInvData> createState() => _AddInvDataState();
}
class _AddInvDataState extends State<AddInvData> {
final _qty = TextEditingController();
List sellerList = [];
#override
Widget build(BuildContext context) {
final providerr = Provider.of<InventoryProvider>(context);
return ListView.builder(
padding: const EdgeInsets.all(15.0),
physics: const ScrollPhysics(),
shrinkWrap: true,
itemCount: widget.snapshot.data!.size,
itemBuilder: (context, index) {
Map<String, dynamic> sellerData =
widget.snapshot.data!.docs[index].data() as Map<String, dynamic>;
int sellerQty = int.parse(sellerData['qty']);
return InkWell(
onTap: () {
showDialog(
context: context,
useRootNavigator: false,
builder: (context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(40),
),
elevation: 16,
child: Container(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Quantity in kg: '),
const SizedBox(width: 10),
Container(
height: 60,
width: 60,
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
),
child: TextFormField(
controller: _qty,
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
border: InputBorder.none,
),
),
),
],
),
const SizedBox(height: 50),
TextButton(
onPressed: () async {
Map<String, dynamic> seller = {
'date': sellerData['date'],
'qty': _qty.text,
};
sellerList.add(seller);
providerr.getData(sellerList: sellerList);
print(providerr.inventoryData['sellerList']);
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const InvDetails(),
));
},
child: const Text('ASSIGN'),
),
],
),
),
);
},
);
},
child: Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 30),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
sellerData['date'],
style: const TextStyle(fontSize: 18),
),
Text(
'${sellerData['qty']} kg',
style: const TextStyle(fontSize: 18),
),
],
),
),
);
},
);
}
}
inv_details.dart
class InvDetails extends StatelessWidget {
const InvDetails({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: TextButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => const AddInv(),
));
},
child: const Text('Add Inventory'),
),
),
);
}
}
inv_provider.dart
class InventoryProvider with ChangeNotifier {
Map<String, dynamic> inventoryData = {};
getData({List? sellerList}) {
if (sellerList != null) {
inventoryData['sellerList'] = sellerList;
}
notifyListeners();
}
}
Here printing at the first
[{date: 10/31/2022, qty: 1}]
When I navigate to InvDetails from AddInvData and when the button is clicked it's printing
[{date: 11/25/2022, qty: 1}]
Data is not updating
But if I didn't navigate.
i.e If I stay in AddInvData and added quantity it is updating.
inv_data.dart (Added textbutton part only ) removed navigate
TextButton(
onPressed: () async {
Map<String, dynamic> seller = {
'date': sellerData['date'],
'qty': _qty.text,
};
sellerList.add(seller);
providerr.getData(sellerList: sellerList);
print(providerr.inventoryData['sellerList']);
},
prints
[{date: 10/31/2022, qty: 1}]
[{date: 10/31/2022, qty: 1}, {date: 11/25/2022, qty: 1}]
Why this is not hapenning when navigate and come back to previous page?

Flutter : Adding item from one list view to another list view

I am trying to select one item from phone contacts list (List view widget)
class PhoneContacts extends StatefulWidget {
const PhoneContacts({Key? key}) : super(key: key);
#override
State<PhoneContacts> createState() => _PhoneContactsState();
}
class _PhoneContactsState extends State<PhoneContacts> {
List<Contact> _contacts = [];
late PermissionStatus _permissionStatus;
late Customer _customer;
#override
void initState(){
super.initState();
getAllContacts();
}
void getAllContacts() async {
_permissionStatus = await Permission.contacts.request();
if(_permissionStatus.isGranted) {
List<Contact> contacts = await ContactsService.getContacts(withThumbnails: false);
setState(() {
_contacts = contacts;
});
}
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Phone Contacts"),
backgroundColor: Colors.indigo[600],
),
body: Container(
padding: const EdgeInsets.all(5),
child: ListView.builder(
itemCount: _contacts.length,
itemBuilder: (BuildContext context, int index) {
Contact contact = _contacts[index];
return contactItem(contact);
}
),
),
);
}
Widget contactItem(Contact contact){
return ListTile(
onTap: () {
Navigator.of(context).push(MaterialPageRoute(builder: (context)=>Dashboard(contact)));
},
leading: const CircleAvatar(
backgroundColor: Colors.pinkAccent,
child: Icon(Icons.person_outline_outlined)),
title : Text(contact.displayName.toString()),
subtitle: Text(contact.phones!.first.value.toString()),
);
}
}
and insert and display it to dashboard list (another List view widget)
class Dashboard extends StatefulWidget {
final Contact? contact;
const Dashboard([this.contact]);
#override
State<Dashboard> createState() => _DashboardState();
}
class _DashboardState extends State<Dashboard> {
final Color? themeColor = Colors.indigo[600];
late GlobalKey<RefreshIndicatorState> refreshKey;
late List<CardGenerator> existingCustomerContactList = getCustomerContactList();
#override
void initState(){
super.initState();
refreshKey=GlobalKey<RefreshIndicatorState>();
}
void addCustomerContact() {
existingCustomerContactList.add(
CardGenerator(
Text(widget.contact!.displayName.toString()),
const Icon(Icons.account_circle),
Text(widget.contact!.phones!.first.value.toString())));
}
List<CardGenerator> getCustomerContactList () {
existingCustomerContactList = [
CardGenerator(
const Text('Dave', style: TextStyle(fontSize: 24.0), textAlign: TextAlign.start,),
const Icon(Icons.account_circle, size: 100, color: Colors.white,),
const Text('Address 1')),
CardGenerator(
const Text('John', style: TextStyle(fontSize: 24.0)),
const Icon(Icons.account_circle, size: 100, color: Colors.white),
const Text('Address 2')),
CardGenerator(
const Text('Richard', style: TextStyle(fontSize: 24.0)),
const Icon(Icons.account_circle, size: 100, color: Colors.white),
const Text('Address 3')),
];
return existingCustomerContactList;
}
Future<void> refreshList() async {
await Future.delayed(const Duration(seconds: 1));
setState(() => {
addCustomerContact(),
getCustomerContactList()
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[50],
appBar: AppBar(
title: const Text("Dashboard"),
backgroundColor: themeColor,
),
body: RefreshIndicator(
key: refreshKey,
onRefresh: () async {
await refreshList();
},
child: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: existingCustomerContactList.length,
key: UniqueKey(),
itemBuilder: (BuildContext context, int index) {
return OpenContainer(
closedColor: Colors.transparent,
closedElevation: 0.0,
openColor: Colors.transparent,
openElevation: 0.0,
transitionType: ContainerTransitionType.fadeThrough,
closedBuilder: (BuildContext _, VoidCallback openContainer) {
return Card(
color: Colors.white,
child: GestureDetector(
onTap: openContainer,
child: SizedBox(
height: 140,
child: Row(
children: [
Container(
decoration: const BoxDecoration(
color: Colors.indigo,
borderRadius: BorderRadius.only(topLeft: Radius.circular(7.0),bottomLeft: Radius.circular(7.0))
),
height: 140,
width: 120,
child: existingCustomerContactList[index].icon,
),
Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: existingCustomerContactList[index].title,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: existingCustomerContactList[index].address,
),
],
)
],
),
),
),
);
},
openBuilder: (BuildContext _, VoidCallback openContainer) {
return ConsumerHome();
}
);
}),
),
],
),
),
);
}
}
I found the
selected item has been added to the Dashboard items list but when I refresh it it doesn't newly added item in the dashboard list view.
I am a newcomer in flutter please bare with me. I already did my search for this problem unfortunately, no luck.
Change the order of execution. You are adding the item in the list and then making a new list again in the current order
addCustomerContact(),
getCustomerContactList()
change this to
getCustomerContactList()
addCustomerContact(),

error: The argument type 'Null' can't be assigned to the parameter type 'Map<String, dynamic>'

I am writing my first Flutter App with some online tutorials and I found error that I can't fix it.
I am trying to add Navigation by Navigator, but I can't understand why it doesn't work.
Once I am using Navigator in GestureDetector and it works fine, but I don't know what I supposed to do in floatingActionButton to make it work the same way. Note(NoteMode.Adding, null) probably should be something else instead null, because this null is making error (error from title). Can someone explain me what I am doing wrong and what I don't undarstand
Note List
#override
_NoteListState createState(){return _NoteListState();}
}
class _NoteListState extends State<NoteList> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Notes"),
),
body: FutureBuilder(
future: NoteProvider.getNoteList(),
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
final notes = snapshot.data;
return ListView.builder(
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) =>
Note(NoteMode.Editing, (notes as dynamic)[index]))
);
},
child: Card(
child: Padding(
padding: const EdgeInsets.only(
top: 30.0, bottom: 30.0, left: 13, right: 22),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_NoteTitle((notes as dynamic)[index]['title']),
Container(height: 3,),
_NoteText((notes as dynamic)[index]['text']),
],
),
),
),
);
},
itemCount: notes.length,
);
}
return Center(child: CircularProgressIndicator());
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => Note(NoteMode.Adding, null)));
},
child: Icon(Icons.add),
),
);
}
}
Note
enum NoteMode{
Editing,
Adding
}
class Note extends StatefulWidget{
final NoteMode noteMode;
final Map<String, dynamic> note;
Note(this.noteMode, this.note,);
#override
State<Note> createState() => _NoteState();
}
class _NoteState extends State<Note> {
final TextEditingController _titleController = TextEditingController();
final TextEditingController _textController = TextEditingController();
List<Map<String, String>> get _notes => NoteInheritedWidget.of(context).notes;
#override
void didChangeDependencies(){
if(widget.noteMode == NoteMode.Editing){
_titleController.text = widget.note['title'];
_textController.text = widget.note['text'];
}
super.didChangeDependencies();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
widget.noteMode == NoteMode.Adding ? 'Add note' : 'Edit note',
),
),
body: Padding(
padding: const EdgeInsets.all(40.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
controller: _titleController,
decoration: InputDecoration(
hintText: "Note title",
),
),
Container(height: 8,),
TextField(
controller: _textController,
decoration: InputDecoration(
hintText: "Note text",
),
),
Container(height: 15,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
_NoteButton('SAVE', Colors.lightBlue, (){
final title = _titleController.text;
final text = _textController.text;
if(widget.noteMode == NoteMode.Adding){
NoteProvider.insertNote({
'title': title,
'text': text
});
} else if (widget.noteMode == NoteMode.Editing){
NoteProvider.updateNote( {
'id': widget.note['id'],
'title': _titleController.text,
'text': _textController.text,
});
}
Navigator.pop(context);}),
_NoteButton('DISCARD', Colors.grey, (){Navigator.pop(context);}),
widget.noteMode == NoteMode.Editing ?
_NoteButton('DELETE', Colors.redAccent, () async {
await NoteProvider.deleteNote(widget.note['id']);
Navigator.pop(context);})
: Container(),
],
)
],
),
),
);
}
}
Either you have to pass Map in place of null because you are receiving a Map on that page
Navigator.push(context, MaterialPageRoute(builder: (context) => Note(NoteMode.Adding, {"key":"value"})));
or you have to make Map nullable as
class Note extends StatefulWidget{
final NoteMode noteMode;
final Map<String, dynamic>? note;
Note(this.noteMode, this.note,);
#override
State<Note> createState() => _NoteState();
}

Passing QuerySnapshot data to TabView so I can access it in pages in each tab

I have added a TabBar to my flutter app. It was pretty easy. I have created a new page for tab 1 and moved an existing page to tab 2. Both of these pages should display data from a Firestore QuerySnapshot but I don't know how to do this.
I have a screen, AgentDashBoardScreen, that creates a QuerySnapshot and builds a ListView with the data retrieved by the query.
In the onTap property of each ListTile the user is taken to the TransactionHomeScreen which has the TabBar widget in it. Also, I want to pass the QuerySnapshot to this page. Below is the code for AgentDashBoardScreen.
class AgentDashboardScreen extends StatefulWidget {
static const String id = 'agent_dashboard_screen';
#override
_AgentDashboardScreenState createState() => _AgentDashboardScreenState();
}
class _AgentDashboardScreenState extends State<AgentDashboardScreen> {
bool showSpinner = false;
//int _selectedIndex = 0;
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/images/Appbar_logo.png',
fit: BoxFit.cover, height: 56),
],
),
),
drawer: Drawer(
child: ListView(
children: <Widget>[
ListTile(
title: Text("Agent Profile"),
onTap: () {
MainScreen.of(context)?.setIndex(3); // Added this for BottomNavigationBar sync
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => AgentProfileScreen()));
},
),
],
),
),
body: SafeArea(
child: Container(
child: StreamBuilder(
stream: FirestoreService().getAgencyTrxns(context),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Center(
child: const Text(
'Loading...',
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.bold),
));
return new ListView.builder(
itemCount: (snapshot.data! as QuerySnapshot).docs.length,
itemBuilder: (BuildContext context, int index) {
Trxns trxns = Trxns.fromFirestore(
(snapshot.data! as QuerySnapshot).docs[index]
.data() as Map<String, dynamic>);
return ListTile(
isThreeLine: true,
title: Text(
'Client: ${trxns.clientFName ?? 'n/a'} ${trxns
.clientLName ?? 'n/a'}',
style: TextStyle(
fontWeight: FontWeight.w900,
color: Colors.blueAccent),
),
subtitle: Text.rich(TextSpan(
text:
'${trxns.propertyAddress ?? 'n/a'}, ${trxns
.propertyCity ?? 'n/a'}, ${trxns
.propertyState ?? 'n/a'}',
children: <TextSpan>[
TextSpan(
text:
'\nPrice: ${trxns!.contractPrice == null ? 'n/a' : NumberFormat.simpleCurrency().format(trxns.contractPrice)}\nStatus: ${trxns.trxnStatus ?? 'n/a'}',
style: TextStyle(
fontWeight: FontWeight.w900,
color: Colors.blueGrey),
)
])),
trailing: Text('MLS#: ${trxns.mlsNumber ?? 'n/a'}\n${trxns.clientType}'),
onTap: () {
MainScreen.of(context)?.setIndex(2); // Added this for BottomNavigationBar sync
globals.newTrxn = false;
Navigator.of(context).push(MaterialPageRoute(
builder: (context) =>
**TrxnHomeScreen(
(snapshot.data! as QuerySnapshot).docs[index])));**
},
);
});
},
),
),
),
));
}
}
Here is the code for the TrxnHomeScreen.
class TrxnHomeScreen extends StatefulWidget {
static const String id = 'trxn_home_screen';
final QueryDocumentSnapshot? trxns;
TrxnHomeScreen([this.trxns]);
#override
_TrxnHomeScreenState createState() => _TrxnHomeScreenState();
}
class _TrxnHomeScreenState extends State<TrxnHomeScreen> with SingleTickerProviderStateMixin {
bool showSpinner = false;
TabController? _trxnTabController;
#override
void initState() {
super.initState();
_trxnTabController = TabController(length: 3, vsync: this);
}
#override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset('assets/images/Appbar_logo.png',
fit: BoxFit.cover, height: 56),
],
),
bottom: TabBar(
indicatorWeight: 5,
indicatorColor: Colors.orange,
controller: _trxnTabController,
tabs: [
Tab(
text: "STATUS"
),
Tab(
text: "DETAILS",
),
Tab(
text: "TASKS",
),
],
),
),
body: SafeArea(
child: Container(
child: TabBarView(
controller: _trxnTabController,
children: <Widget>[
TransactionStatusScreen(widget.trxns),
TransactionDetailScreen(widget.trxns),
Text('Tasks'),
])
),
),
)),
);
}
}
Here is the code for the TransactionDetailScreen.
class TransactionDetailScreen extends StatefulWidget {
static const String id = 'transaction_detail_screen';
final QueryDocumentSnapshot? trxns;
TransactionDetailScreen([this.trxns]);
#override
_TransactionDetailScreenState createState() =>
_TransactionDetailScreenState();
}
class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
getTrxn() async {
final DocumentSnapshot _mlsId =
await mlsRef.doc(globals.mlsId).get();
_mlsSearchLink = _mlsId.get('mlsNbrSearch');
if (widget.trxns == null) {
globals.newTrxn = true;
} else {
globals.newTrxn = false;
}
#override
void initState() {
getTrxn();
super.initState();
}
#override
Widget build(BuildContext context) {
}
}
From the code, you are passing the QueryDocumentSnapshot to TransactionHomeScreen but the code you provided for the tab bar is TrxnHomeScreen.