I am trying to make an app that has a button that whenever you press it, it will pop up a bunch of TextFields to input stuff. However, I keep getting the "too many positional arguments 0 expected but 1 found" error. For some reason, this only happens to my first TextField and not to any of the others (if I delete the first TextField the error moves to the new first). I tried putting a semicolon in front of the first TextField and that made that error go away, but then I get a new error of ") expected" and if I put a ), then it auto comments out all my TextFields. What am I doing wrong? (btw I have the correct imports at the top, just not sure if that is sensitive data so I'm leaving that out of this post)
class AdminScreen extends StatefulWidget {
const AdminScreen({Key? key}) : super(key: key);
@override
State<AdminScreen> createState() => _AdminScreenState();
}
class _AdminScreenState extends State<AdminScreen> {
reloadUser() {
setState(() {});
}
//this section is for adding stuff to database
String name = "";
String description = "";
String dateFound = "";
String locationFound = "";
String currentLocation = "";
String claimed = "";
bool addDataVisible = false;
//end of this section
TextEditingController nameController = TextEditingController();
TextEditingController descriptionController = TextEditingController();
TextEditingController dateController = TextEditingController();
TextEditingController locationController = TextEditingController();
TextEditingController storedController = TextEditingController();
TextEditingController claimedController = TextEditingController();
showWidget(){
setState(() {
addDataVisible = true ;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Admin'),
),
body: FirebaseAuth.instance.currentUser == null ? LoginButton(
updateState: reloadUser,) : //Text('logged in'),
TextButton(
child: const Text('Click Here to Add New Item to Database'),
onPressed: showWidget(),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.blue),
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
),
//render the new widgets
TextField(
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Name of Item',
),
controller: nameController,
Visibility(
visible: addDataVisible,
),
onChanged: (text) {
setState(() {
name = text;
});
},
//for description
);
TextField(
controller: descriptionController,
Visibility(
visible: addDataVisible,
),
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Description of Item',
),
onChanged: (text) {
setState(() {
description = text;
});
},
//for location found
);TextField(
controller: locationController,
Visibility(
visible: addDataVisible,
),
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Location Found of Item',
),
onChanged: (text) {
setState(() {
locationFound = text;
});
},
//for current location
);TextField(
controller: storedController,
Visibility(
visible: addDataVisible,
),
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Current Location of Item',
),
onChanged: (text) {
setState(() {
currentLocation = text;
});
},
//for timestamp
);TextField(
controller: dateController,
Visibility(
visible: addDataVisible,
),
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Time Found for Item',
),
onChanged: (text) {
setState(() {
dateFound = text;
});
},
//for claimed or not
);TextField(
controller: claimedController,
Visibility(
visible: addDataVisible,
),
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Item Been Claimed? (Put T or F please)',
),
onChanged: (text) {
setState(() {
claimed = text;
});
},
);TextButton(
child: const Text('Click Here to Submit'),
onPressed: _submit,
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.blue),
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
);
},
);
}
}
_submit(){
}
CodePudding user response:
you can not add more than one widget in saffold's body, so you have to add your element's as children in a column
CodePudding user response:
Is this what you're trying to achieve?
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Admin'),
),
body: SingleChildScrollView(
child: Column(children: [
FirebaseAuth.instance.currentUser == null ? LoginButton(
updateState: reloadUser,) : //Text('logged in'),
TextButton(
child: const Text('Click Here to Add New Item to Database'),
onPressed: showWidget(),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.blue),
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
),
//render the new widgets
Visibility(
visible: addDataVisible,
child: Column(
children: [
TextField(
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Name of Item',
),
controller: nameController,
onChanged: (text) {
setState(() {
name = text;
});
},
//for description
),
TextField(
controller: descriptionController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Description of Item',
),
onChanged: (text) {
setState(() {
description = text;
});
},
//for location found
),
TextField(
controller: locationController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Location Found of Item',
),
onChanged: (text) {
setState(() {
locationFound = text;
});
},
//for current location
),
TextField(
controller: storedController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Current Location of Item',
),
onChanged: (text) {
setState(() {
currentLocation = text;
});
},
//for timestamp
),
TextField(
controller: dateController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Time Found for Item',
),
onChanged: (text) {
setState(() {
dateFound = text;
});
},
//for claimed or not
),
TextField(
controller: claimedController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Item Been Claimed? (Put T or F please)',
),
onChanged: (text) {
setState(() {
claimed = text;
});
},
),
],
),
),
TextButton(
child: const Text('Click Here to Submit'),
onPressed: _submit,
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.blue),
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
),
]),
),
);
}