not showing data in year dropdown in flutter - list

this is my list to show data from string type list-
List<Widget> _getYearList() {
List<Widget> list = List<Widget>();
for (int index = 0; index < 30; index++) {
list.add(Container(
alignment: Alignment.center,
child: Text(
UtilString.years[index],
//'$index',
style: TextStyle(fontSize: 16),
),
));
}
return list;
}
this is designing view -
SizedBox(width: 8),
Text(
'${UtilString.year} : ',
style: TextStyle(
fontSize: 16,
color: Colors.grey[700],
),
),
Container(
height: 100,
width: 52,
child: CupertinoPicker(
squeeze: 1.3,
itemExtent: 30,
backgroundColor: Colors.white,
children: _getYearList(),
scrollController: FixedExtentScrollController(
initialItem: _year - 1,
),
onSelectedItemChanged: (item) {
setState(() {
_year = item + 1;
});
},
),
),
],
),
defind data
static final List years = <String>['1990', '1991', '1992', '1993 till 2020];

Related

The selected dropdown button value will initiate to its values when saving to a list (Flutter)

I faced an issue when I saved my selected dropdown value to a list. The selected value will return to its initiated value but not the selected value when I added it to the list but it works well before that. Thank you for your help!
This is the selected value output when I clicked the dropdown button
enter image description here
This is the output of the selected value when added to the list
enter image description here
setupstore.dart
class _SetupStoreState extends State<SetupStore> {
final formKey = GlobalKey<FormState>();
final category = Category();
List subCategoryList = [];
PlatformFile? selectedFile;
List listing = [];
String listingImagePath = '';
String listingImageName = '';
String selectedCategory = 'Food';
String selectedSubCategory = 'Malay Cuisine';
String price = '';
String listingName = '';
String listingDescription = '';
bool isSelected = true;
List attribute = [];
int attributeValueNumber = 2;
int attributeNumber = 1;
//select file from local device
Future selectFile() async {
final result = await FilePicker.platform.pickFiles(
allowMultiple: false,
type: FileType.custom,
allowedExtensions: ['png', 'jpg'],
);
if (result == null) return;
listingImagePath = result.files.single.path!;
listingImageName = result.files.single.name;
setState(() {
selectedFile = result.files.first;
});
}
#override
Widget build(BuildContext context) {
final Storage storage = Storage();
final userId = Provider.of<MyUser>(context).uid;
return GestureDetector(
onTap: () {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus) {
currentFocus.unfocus();
}
},
child: Scaffold(
body: SafeArea(
child: Container(
margin: const EdgeInsets.all(5),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 40, child: TopAppBar()),
const TitleAppBar(
title: '2: Set Up Your Store',
iconFlex: 1,
titleFlex: 3,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: SizedBox(
height: 15,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Listing (${listing.length})',
style: ratingLabelStyle,
),
],
),
),
),
const SizedBox(
height: 5,
),
SizedBox(
height: 510,
child: Form(
key: formKey,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 100,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
const Text('Image',
style: boldContentTitle),
SizedBox(
height: 20,
child: IconButton(
icon: const Icon(Icons.file_upload),
iconSize: 20,
padding: const EdgeInsets.all(0),
onPressed: selectFile,
),
),
const SizedBox(width: 100),
const Text('Listing Category',
style: boldContentTitle),
]),
const SizedBox(height: 5),
Row(
children: [
Expanded(
flex: 4,
child: Container(
width: 170,
height: 65,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: const Color.fromARGB(
250, 233, 221, 221),
borderRadius:
BorderRadius.circular(5),
),
child: ClipRRect(
borderRadius:
BorderRadius.circular(10),
child: (selectedFile != null)
? Image.file(
i.File(selectedFile!.path!),
fit: BoxFit.cover,
)
: null,
),
),
),
const SizedBox(
width: 10,
),
Expanded(
flex: 4,
child: Column(
children: [
ItemDropdownButton(
itemValue: selectedCategory,
items: category.category,
onChanged: (val) {
setState(() {
selectedCategory = val!;
print(
"category: $selectedCategory");
});
},
),
const SizedBox(height: 5),
ItemDropdownButton(
itemValue: selectedCategory ==
category.category[0]
.toString()
? selectedSubCategory =
category.subCategory[0]
[0]
: selectedCategory ==
category.category[1]
? selectedSubCategory =
category.subCategory[
1][0]
: selectedSubCategory =
category.subCategory[
2][0],
// itemValue: selectedSubCategory,
items: selectedCategory ==
category.category[0]
.toString()
? subCategoryList =
category.subCategory[0]
: selectedCategory ==
category.category[1]
.toString()
? subCategoryList =
category
.subCategory[1]
: subCategoryList =
category
.subCategory[2],
onChanged: (val) {
setState(() {
selectedSubCategory = val!;
print(
"subCategory: $selectedSubCategory");
});
},
)
],
))
],
),
],
),
),
SizedBox(
height: 65,
child: Column(
children: [
Row(
crossAxisAlignment:
CrossAxisAlignment.start,
children: const [
Text('Listing Price',
style: boldContentTitle),
SizedBox(width: 110),
Text('Listing Name',
style: boldContentTitle),
]),
const SizedBox(height: 5),
SizedBox(
height: 35,
child: Row(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Expanded(
child: SizedBox(
width: 170,
child: StringTextArea(
label: 'Price',
textLine: 1,
onChanged: (val) {
setState(() {
price = val;
});
},
),
),
),
const SizedBox(
width: 10,
),
Expanded(
child: StringTextArea(
label:
'Nasi Lemak / Face Mask / Design',
textLine: 1,
onChanged: (val) {
listingName = val;
},
),
),
],
),
)
],
),
),
],
),
),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
height: 30,
width: 100,
child: PurpleTextButton(
buttonText: 'Add listing',
onClick: () {
// for (int i = 0; i < listing.length; i++) {
setState(() {
listing.add({
"listingImagePath": listingImagePath,
"selectedCategory": selectedCategory,
"selectedSubCategory": selectedSubCategory,
"price": price,
"listingName": listingName,
"listingDescription": listingDescription
});
print(listing);
// Navigator.pop(context);
});
},
),
),
],
),
)
],
),
),
),
),
),
);
}
}
dropdownmenu.dart
class ItemDropdownButton extends StatefulWidget {
final String itemValue;
final List<dynamic> items;
final void Function(String?) onChanged;
const ItemDropdownButton(
{Key? key,
required this.itemValue,
required this.items,
required this.onChanged})
: super(key: key);
#override
_ItemDropdownButtonState createState() => _ItemDropdownButtonState();
}
class _ItemDropdownButtonState extends State<ItemDropdownButton> {
#override
Widget build(BuildContext context) {
return SizedBox(
height: 30,
child: DropdownButtonFormField<String>(
isExpanded: true,
decoration: const InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1),
borderRadius: BorderRadius.zero),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1),
borderRadius: BorderRadius.zero),
contentPadding: EdgeInsets.symmetric(horizontal: 10),
),
value: widget.itemValue,
iconSize: 18,
items: widget.items.map<DropdownMenuItem<String>>((items) {
return DropdownMenuItem<String>(
value: items,
child: Text(
items,
style: ratingLabelStyle,
overflow: TextOverflow.ellipsis,
),
);
}).toList(),
onChanged: widget.onChanged,
),
);
}
}

How to set value on selected items with checkboxListTile

What is the correct way to Setstate of checkboxListTile
to get both toggle button and added value to it?
What I want is when you check the box, You see the check button.
then the value added into the base price. Please kindly help.
CheckboxListTile(
activeColor: Colors.blue,
dense: true,
//font change
title: new Text(
listTopping[i].price.toStringAsFixed(0) +
' บาท',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
value: listTopping[i].isCheck,
secondary: Container(
height: 50,
width: 300,
child: Text(
listTopping[i].topping,
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
),
onChanged: (bool? val) {
itemChange(val!, i);
},
),
Here is the setstate that I believe is wrong...
void itemChange(bool val, int i) {
setState(() {
listTopping[i].isCheck = val;
});
}
}
Here is a small example of your code. Since you didn't provide the AddonTopping class I created a simply version for myself. You can try it out and run this Widget in your MaterialApp. Everything should worked as expected.
class AddonTopping {
AddonTopping({
required this.id,
required this.topping,
required this.isCheck,
required this.price,
});
final int id;
final String topping;
bool isCheck;
final int price;
}
class Americano extends StatefulWidget {
#override
_AmericanoState createState() => _AmericanoState();
}
class _AmericanoState extends State<Americano> {
List<AddonTopping> listTopping = [
AddonTopping(
id: 8,
topping: 'Whipcream',
price: 0,
isCheck: true,
),
AddonTopping(
id: 9,
topping: 'Javachip',
price: 30,
isCheck: false,
),
AddonTopping(
id: 10,
topping: 'SoyMilk',
price: 20,
isCheck: false,
),
AddonTopping(
id: 11,
topping: 'ExtraSyrup',
price: 30,
isCheck: false,
),
];
#override
Widget build(BuildContext context) {
return Column(
children: [
Text('SUM: ${calculatePrice()}'),
ListView.builder(
shrinkWrap: true,
itemCount: listTopping.length,
itemBuilder: (context, i) => CheckboxListTile(
activeColor: Colors.blue,
dense: true,
//font change
title: Text(
listTopping[i].price.toStringAsFixed(0),
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
value: listTopping[i].isCheck,
secondary: Container(
height: 50,
width: 300,
child: Text(
listTopping[i].topping,
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
),
onChanged: (bool? val) {
itemChange(val!, i);
},
),
),
],
);
}
void itemChange(bool val, int i) {
setState(() {
listTopping[i].isCheck = val;
});
}
double calculatePrice() {
if (listTopping.isNotEmpty) {
double _price = 0.0;
// Get those toppings that are chosen (`isCheck` is true)
final chosenTopping = listTopping.where((element) => element.isCheck);
// Calculate the sum
for (final AddonTopping item in chosenTopping) {
if (item.isCheck) {
_price += item.price;
}
}
return _price;
}
return 0.00;
}
}

Building a List<FlatButton> using Firebase [duplicate]

This question already has answers here:
how to assign future<> to widget in flutter?
(6 answers)
Closed 1 year ago.
I'm building a list of buttons, using Firebase to name each one, but my code presents this error when referencing "_getButtonBar" to the Widget: "The argument type 'Future<List>' can't be assigned to the parameter type 'List'". Should the widget be Future too? Does anyone know what's missing?
class ThemesList extends StatelessWidget {
Future<List<FlatButton>> _getButtonBar(context) async {
List<FlatButton> _list1 = [];
tot = await callReadTotal(); //Receives length to make the loop.
getListCauses(); //Calls Firebase to use arrCauses = List () for child: Text
for (int i = 1; i <= tot; i++) {
_list1.add(
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
side: BorderSide(color: Color.fromRGBO(150, 1, 1, 1)),
),
splashColor: Color.fromRGBO(150, 1, 1, 1),
onPressed: () => {
setChoice(i),
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CausesList()),
),
},
child: Text(
arrCauses[i],
style: TextStyle(
color: Color.fromRGBO(150, 1, 1, 1),
fontSize: 20,
fontFamily: 'Balsamiq_Sans',
),
),
),
);
}
return _list1;
}
#override
Widget build(BuildContext context) {
return Platform.isIOS
? CupertinoPageScaffold(child: null)
: Scaffold(
appBar: AppBar(
title: Text(
'ICare',
style: TextStyle(
color: Color.fromRGBO(150, 1, 1, 1),
fontSize: 40,
fontFamily: 'Balsamiq_Sans',
fontWeight: FontWeight.w500,
),
),
flexibleSpace: Image(
image: AssetImage('assets/images/solidariedade.png'),
color: Color.fromRGBO(255, 200, 200, 0.45),
colorBlendMode: BlendMode.modulate,
fit: BoxFit.cover,
),
),
body: Stack(
children: <Widget>[
Container(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: ButtonBar(
children: _getButtonBar(
context), //<-- Here it points out the error.
alignment: MainAxisAlignment.center,
),
),
),
],
),
);
}
}
Your problem can be solve via two options.
By using StatefulWidget
import 'package:flutter/material.dart';
class ThemesList extends StatefulWidget {
#override
_ThemesListState createState() => _ThemesListState();
}
class _ThemesListState extends State<ThemesList> {
List<FlatButton> _buttonBar = [];
#override
void initState() {
_getButtonBar();
super.initState();
}
_getButtonBar() async {
List<FlatButton> _list1 = [];
tot = await callReadTotal(); //Receives length to make the loop.
getListCauses(); //Calls Firebase to use arrCauses = List () for child: Text
for (int i = 1; i <= tot; i++) {
_list1.add(
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
side: BorderSide(color: Color.fromRGBO(150, 1, 1, 1)),
),
splashColor: Color.fromRGBO(150, 1, 1, 1),
onPressed: () => {
setChoice(i),
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CausesList()),
),
},
child: Text(
arrCauses[i],
style: TextStyle(
color: Color.fromRGBO(150, 1, 1, 1),
fontSize: 20,
fontFamily: 'Balsamiq_Sans',
),
),
),
);
}
_buttonBar = _list1;
setState(() {});
}
#override
Widget build(BuildContext context) {
return Platform.isIOS
? CupertinoPageScaffold(child: null)
: Scaffold(
appBar: AppBar(
title: Text(
'ICare',
style: TextStyle(
color: Color.fromRGBO(150, 1, 1, 1),
fontSize: 40,
fontFamily: 'Balsamiq_Sans',
fontWeight: FontWeight.w500,
),
),
flexibleSpace: Image(
image: AssetImage('assets/images/solidariedade.png'),
color: Color.fromRGBO(255, 200, 200, 0.45),
colorBlendMode: BlendMode.modulate,
fit: BoxFit.cover,
),
),
body: Stack(
children: <Widget>[
Container(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: ButtonBar(
children: _buttonBar,
alignment: MainAxisAlignment.center,
),
),
),
],
),
);
}
}
By using FutureBuilder
import 'package:flutter/material.dart';
class ThemesList extends StatelessWidget {
Future<List<FlatButton>> _getButtonBar(context) async {
List<FlatButton> _list1 = [];
tot = await callReadTotal(); //Receives length to make the loop.
getListCauses(); //Calls Firebase to use arrCauses = List () for child: Text
for (int i = 1; i <= tot; i++) {
_list1.add(
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
side: BorderSide(color: Color.fromRGBO(150, 1, 1, 1)),
),
splashColor: Color.fromRGBO(150, 1, 1, 1),
onPressed: () => {
setChoice(i),
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CausesList()),
),
},
child: Text(
arrCauses[i],
style: TextStyle(
color: Color.fromRGBO(150, 1, 1, 1),
fontSize: 20,
fontFamily: 'Balsamiq_Sans',
),
),
),
);
}
return _list1;
}
#override
Widget build(BuildContext context) {
return Platform.isIOS
? CupertinoPageScaffold(child: null)
: Scaffold(
appBar: AppBar(
title: Text(
'ICare',
style: TextStyle(
color: Color.fromRGBO(150, 1, 1, 1),
fontSize: 40,
fontFamily: 'Balsamiq_Sans',
fontWeight: FontWeight.w500,
),
),
flexibleSpace: Image(
image: AssetImage('assets/images/solidariedade.png'),
color: Color.fromRGBO(255, 200, 200, 0.45),
colorBlendMode: BlendMode.modulate,
fit: BoxFit.cover,
),
),
body: Stack(
children: <Widget>[
Container(
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: FutureBuilder<List<FlatButton>>(
future: _getButtonBar(context),
builder: (context,
AsyncSnapshot<List<FlatButton>> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return Text('Loading....');
break;
default:
if (snapshot.hasError)
return Text('Error: ${snapshot.error}');
else
return ButtonBar(
children: snapshot.data,
alignment: MainAxisAlignment.center,
);
}
}),
),
),
],
),
);
}
}

Flutter Merging List of Images

I was working on merging few images and display it as one.
I have two dart files one is for adding images and other is for displaying the merged result.
first file code is,
class SingleImageUpload extends StatefulWidget {
#override
_SingleImageUploadState createState() {
return _SingleImageUploadState();
}
}
class _SingleImageUploadState extends State<SingleImageUpload> {
List<Object> images = List<Object>();
File _selectedFile;
bool _inProcess = false;
Map data = {};
Readerservice _readerservice;
#override
void initState() {
// TODO: implement initState
super.initState();
setState(() {
images.add("Add Image");
images.add("Add Image");
images.add("Add Image");
images.add("Add Image");
});
}
#override
Widget build(BuildContext context) {
return new MaterialApp(
debugShowCheckedModeBanner: false,
home: new Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
leading: Padding(
padding: EdgeInsets.only(left: 12),
child: IconButton(
icon: Icon(Icons.arrow_back_ios,
color: Colors.black,
size: 30,),
onPressed: () {
Navigator.pushNamed(context, '/');
},
),
),
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children:<Widget>[
Text('Basic AppBar'),
]
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.more_vert,
color: Colors.black,
size: 30,),
onPressed: () {
print('Click start');
},
),
],
),
body:
Column(
children: <Widget>[
SizedBox(height: 10),
Row(children: <Widget>[
Text('Image',
style: TextStyle(
color: Colors.black,
fontSize: 33,
fontWeight: FontWeight.bold,
)),
Text('Merger',
style: TextStyle(
color: Colors.orange,
fontSize: 33,
fontWeight: FontWeight.bold,
)),
]),
SizedBox(height: 40),
Text(' merge it here'),
SizedBox(height: 10),
Expanded(
child: buildGridView(),
),
RaisedButton(
textColor: Colors.white,
color: Colors.orange,
child: Text("Finish",
style: TextStyle(fontSize: 15),),
onPressed: () {
pasimage();
},
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(8.0),
),
),
],
),
),
);
}
Widget buildGridView() {
return GridView.count(
shrinkWrap: true,
crossAxisCount: 3,
childAspectRatio: 1,
children: List.generate(images.length, (index) {
if (images[index] is ImageUploadModel) {
ImageUploadModel uploadModel = images[index];
return Card(
clipBehavior: Clip.antiAlias,
child: Stack(
children: <Widget>[
Image.file(
uploadModel.imageFile,
width: 300,
height: 300,
),
Positioned(
right: 5,
top: 5,
child: InkWell(
child: Icon(
Icons.remove_circle,
size: 20,
color: Colors.red,
),
onTap: () {
setState(() {
images.replaceRange(index, index + 1, ['Add Image']);
});
},
),
),
],
),
);
} else {
return Card(
child: IconButton(
icon: Icon(Icons.add),
onPressed: () {
//popup
showDialog(
context: context,
builder: (context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
elevation: 16,
child: Container(
height: 180.0,
width: 330.0,
child: ListView(
children: <Widget>[
SizedBox(height: 20),
//Center(
Padding(
padding: const EdgeInsets.only(left: 15.0),
child: Text(
"Add a Receipt",
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 24,
color: Colors.black,
fontWeight: FontWeight.bold),
),
),
// ),
SizedBox(height: 20),
FlatButton(
child: Text(
'Take a photo..',
textAlign: TextAlign.left,
style: TextStyle(fontSize: 20),
),
onPressed: () {
_onAddImageClick(index,ImageSource.camera);
Navigator.of(context).pop();
// picker.getImage(ImageSource.camera);
},
textColor: Colors.black,
),
FlatButton(
child: Text(
'Choose from Library..',
style: TextStyle(fontSize: 20),
textAlign: TextAlign.left,
),
onPressed: () {
_onAddImageClick(index,ImageSource.gallery);
Navigator.of(context).pop();
},
textColor: Colors.black,
),
],
),
),
);
},
);
//pop ends
},
),
);
}
}),
);
}
Future _onAddImageClick(int index, ImageSource source ) async {
setState(() {
_inProcess = true;
});
File image = await ImagePicker.pickImage(source: source);
if(image != null){
File cropped = await ImageCropper.cropImage(
sourcePath: image.path,
maxWidth: 1080,
maxHeight: 1080,
compressFormat: ImageCompressFormat.jpg,
androidUiSettings: AndroidUiSettings(
toolbarColor: Colors.black,
toolbarWidgetColor: Colors.white,
//toolbarTitle: "RPS Cropper",
statusBarColor: Colors.deepOrange.shade900,
backgroundColor: Colors.black,
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: false
),
iosUiSettings: IOSUiSettings(
minimumAspectRatio: 1.0,
)
);
this.setState((){
_selectedFile = cropped ;
_inProcess = false;
});
} else {
this.setState((){
_inProcess = false;
});
}
getFileImage(index);
}
void getFileImage(int index) async {
// var dir = await path_provider.getTemporaryDirectory();
setState(() {
ImageUploadModel imageUpload = new ImageUploadModel();
imageUpload.isUploaded = false;
imageUpload.uploading = false;
imageUpload.imageFile = _selectedFile;
imageUpload.imageUrl = '';
images.replaceRange(index, index + 1, [imageUpload]);
});
}
void pasimage(){
Navigator.pushReplacementNamed(context, '/crop',arguments: {
'imageList':ImagesMerge(
images,///required,images list
direction: Axis.vertical,///direction
backgroundColor: Colors.black26,///background color
fit: false,///scale image to fit others
),
});
}
}
class ImageUploadModel {
bool isUploaded;
bool uploading;
File imageFile;
String imageUrl;
ImageUploadModel({
this.isUploaded,
this.uploading,
this.imageFile,
this.imageUrl,
});
}
when I tap the finish button after adding the images it shows an error
The following _TypeError was thrown while handling a gesture:
type 'List' is not a subtype of type 'List'
The page just on captures the data sent from the code above and display the image.
please if anyone know why is the error and help me .
Change the images to List<Object> images = [].

Use Arrows to Navigate through list / change Widget

I am currently struggling to implement a "list" with two QR-Codes.
I want to change the shown QR code by pressing the arrows left and right to it.
"list" because currently I don't use a list view.
Currently it looks like this: Current App
The QR codes are within a ModalBottomSheet.
Here is my code so far:
void _onButtonPressed() {
bool inAppQr = true;
String _output = "QR 1";
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
context: context,
builder: (context) {
return Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
_output,
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0),
),
SizedBox(
height: 30,
),
SizedBox(
height: 5,
width: 150,
child: LinearProgressIndicator(
backgroundColor: Colors.white,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.blueGrey,
),
),
),
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () {
setState(() {
inAppQr = false;
_output = "QR 1";
});
}),
inAppQr == true
? PrettyQr(
typeNumber: 3,
size: 150,
data: 'Test',
errorCorrectLevel: QrErrorCorrectLevel.M,
roundEdges: true)
: PrettyQr(
typeNumber: 3,
size: 150,
data: 'Test 2',
errorCorrectLevel: QrErrorCorrectLevel.M,
roundEdges: true),
IconButton(
icon: Icon(Icons.arrow_forward_ios),
onPressed: () {
setState(() {
_output = "QR 2";
inAppQr = true;
});
}),
],
),
]),
);
});
}
Thanks for your help!
Solution found thanks to Zeeshan Hussain!
I added a StatefulBuilder with the StateSetter newState
This code worked for me:
void _onButtonPressed() {
bool inAppQr = true;
String _output = "QR 1";
showModalBottomSheet(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
context: context,
builder: (context) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter newState) {
return Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
_output,
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 15.0),
),
SizedBox(
height: 30,
),
SizedBox(
height: 5,
width: 150,
child: LinearProgressIndicator(
backgroundColor: Colors.white,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.blueGrey,
),
),
),
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () {
newState(() {
inAppQr = true;
_output = "QR 1";
});
}),
inAppQr == true
? PrettyQr(
typeNumber: 3,
size: 150,
data: 'Test',
errorCorrectLevel: QrErrorCorrectLevel.M,
roundEdges: true)
: PrettyQr(
typeNumber: 3,
size: 150,
data: 'Test 2',
errorCorrectLevel: QrErrorCorrectLevel.M,
roundEdges: true),
IconButton(
icon: Icon(Icons.arrow_forward_ios),
onPressed: () {
newState(() {
_output = "QR 2";
inAppQr = false;
});
}),
],
),
]),
);
},
);
});