how to do upload image within steps method in flutter - flutter

List<Step> steps = [
Step(
isActive: false,
state: StepState.editing,
title: const Text('Id Proof'),
content: Column(
children: <Widget>[
OutlineButton(
onPressed: chooseImage,
child: Text('Choose Image'),),
showImage(),
OutlineButton(
onPressed: startUpload,
child:Text(Upload Image),
),
Text(status,textAlign:TextAlign.center,style:TextStyle(color:Colors.green))
],
),
),
];
Unable to initialize chooseImage, showImage, startUpload. I have tried to initiate above the steps starting. showing errors
Only static members can be accessed in initializers

chooseImage & startUpload are not functions, if you created a function
void chooseImage() {
// add image picking code here
}
then you need to change
onPressed: chooseImage,
to
onPressed: chooseImage(),
if you didn't make those functions you could also do
onPressed: () {
// add image picking code here
}

Related

How to fix "Exception caught by image resource service"

I have created a resources folder to store my images.
part of 'resources.dart';
class IconImages {
IconImages._();
static const String test1 = 'assets/images/test1.jpg';
static const String test2 = 'assets/images/test2.jpg';
static const String test3 = 'assets/images/test3.jpg';
}
I write them to the Map collection
final imagesIcon = <int, String>{
1: IconImages.test1,
2: IconImages.test2,
3: IconImages.test3,
};
and then pass the recorded images to the button.
icon: Image(image: AssetImage(imagesIcon.values.toString())),
// full button
Column(
children: [
Container(
color: Colors.lightBlueAccent,
child: IconButton(
icon: Image(image: AssetImage(imagesIcon.values.toString())),
onPressed: () {},),
),
SizedBox(height: 40,),
Container(
color: Colors.lightBlueAccent,
child: IconButton(
icon: Image(image: AssetImage(imagesIcon.values.toString())),
onPressed: () {},),
),
SizedBox(height: 40,),
Container(
color: Colors.lightBlueAccent,
child: IconButton(
icon: Image(image: AssetImage(imagesIcon.values.toString())),
onPressed: () {},),
),
],
),
When I execute my code, I get the following exception
Everything works when I transmit the image in this form
icon: Image(image: AssetImage(IconImages.test2)),
But when I try to get a path from Map in this way, the above error is obtained
icon: Image(image: AssetImage(imagesIcon.values.toString())),
You are using your map wrong:
IconButton(
icon: Image(image: AssetImage(imagesIcon[1].toString())),
onPressed: () {},
),
I think it may be because you're passing icons as strings. Instead of using images with a class like:
ImageIcon(
AssetImage("images/icon.png"),
color: Colors.red,
size: 24,
),
Edit: after recreating the situation in my project I've found the reason behind that. You use imagesIcon.values.toString() to pass the value of an Icon. Did you check what this function returns? In my case it returned:
(assets/images/test1.jpg, assets/images/test2.jpg,
assets/images/test3.jpg)
No wonder the image is unreadable according to flutter because that is not a proper path or file.
Instead you can use your solution like this:
imagesIcon.values.elementAt(1) //0,1,2 whatever index you need from map

not able to define web links that will open when icon button is pressed in listview builder which is already under expantionbar

(question1) i am not able to think how to pass 3 weblink link ( google.com, yahoo.com, youtube.com) that will open when 3 corresponding icons in topic 1 are pressed in code on :
https://github.com/sandeepnarula999/FlutterProjects/blob/main/ListViewUnderExpansionTile
pls try to share the complete code if u are able to resolve my issue ..as i shared full code above...pls do
not share just steps of how to do coz that may add up to errrors when i try
(question2)
As per below image suggestion when i try to change code from line 7 to 10 in abve code link i get errors.. are u able to get zero error with this below approach in image
Solution : add three Flexible widgets in the Row widget ;)
if (root.children.isEmpty) {
return ListTile(
title: Text(root.title),
subtitle: root.subtitle == null ? null : Text(root.subtitle!),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: IconButton(
onPressed: () {},
icon: const Icon(Icons.auto_stories),
iconSize: 30,
tooltip: 'Documents',
),flex: 1,
),
Flexible(
child: IconButton(
onPressed: () {},
icon: const Icon(Icons.video_collection_rounded),
iconSize: 30,
tooltip: 'Videos',
),
flex: 1,
),
Flexible(
child: IconButton(
onPressed: () {},
icon: const Icon(Icons.favorite),
iconSize: 20,
tooltip: 'Shortlist',
),flex: 1,
),
],
),
);
}
enter image description here

GetX not showing the updated value

I am trying a simple pop-up that should increment everytime I press the 'Use' button. Using the print command, it is showing the correct current value everytime I press. But for the Text itself, it is just staying a constant value. Any suggestion to fix this? Thanks!
showUsePopup() async {
AwesomeDialog(
context: globalScaffoldKey.currentContext!,
dialogType: DialogType.NO_HEADER,
dismissOnTouchOutside: false,
headerAnimationLoop: false,
animType: AnimType.SCALE,
body: Column(
children: [
Row(
children: [
Text('${controller.numOfItemObs.value}'),
ElevatedButton(
onPressed: () {
controller.numOfItemObs.value++;
print('Current value: ${controller.numOfItemObs.value}');
},
child: const Text('Use'),
),
],
),
],
),
showCloseIcon: false,
btnOkOnPress: () async {},
).show();
}
You need to wrap up the Text widget with Obx. It will update the Text value whenever the changes happen. Here is the example that you can follow.
Obx(
() => Text('${controller.numOfItemObs.value}')')
),

Flutter error "Multiple widgets used the same GlobalKey" - using ScreenShot with SocialShare plugins

I'm not sure where to find the extra widget sharing the same global key as another widget in my app. I'm using the Screenshot and Social Share plugins.
https://pub.dev/packages/screenshot
https://pub.dev/packages/social_share
I'd like to upload a screenshot when sharing to social media such as Facebook Messenger. But I'm getting the following error in my console which occurred only after I added the screenshot controller;
Flutter Multiple widgets used the same GlobalKey
Where am I getting this problem? I created the screenshot instance within the state;
class _StageBuilderState extends State<StageBuilder> {
ScreenshotController screenshotController = ScreenshotController();
Here's the build;
Widget createViewItem() {
return Screenshot(
controller: screenshotController,
Column(
children: <Widget>[
child: Image.network( myavatar),
child: IconButton(
icon: Icon(Icons.share),
onPressed: () async {
await screenshotController.capture().then((image) async {
SocialShare.shareOptions("http://myurl", imagePath: image.path);
}
);
},
),
],
),
),
}
So where's this extra widget sharing the same global key as something else in my app? Where should I start troubleshooting?
Turns out I had to make the Screenshot controller local and put it here;
Widget createViewItem() {
ScreenshotController _screenshotController = ScreenshotController();
return Screenshot(
controller: screenshotController,
Column(
children: <Widget>[
child: Image.network( myavatar),
child: IconButton(
icon: Icon(Icons.share),
onPressed: () async {
await screenshotController.capture().then((image) async {
SocialShare.shareOptions("http://myurl", imagePath: image.path);
}
);
},
),
],
),
),
}

Dynamically added widget works only after route change

I am using the flutter Slidable widget inside a SliverList, where the list elements are pulled from an array. I use setState to update the list.
The problem I am having is that after the list update, I can see all new elements correctly, but the slidable functionality doesn't work. However, after entering a new page with push and leaving with pop, the slidable functionality starts working.
Why is this happening?
return SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) => Card(
child: InkWell(
child: Slidable(
key: Key(_fileList[index].key),
actionPane: SlidableDrawerActionPane(),
child: Container(
child: ListTile(
onTap: () {
...
},
title: Text(_fileList[index].subtitle),
subtitle: Text(_fileList[index].subtitle),
),
),
secondaryActions: <Widget>[
IconSlideAction(
caption: 'Delete',
color: Colors.red,
icon: Icons.delete,
onTap: () {
...
}
),
],
),
),
),
childCount: _fileList.length,
),
);
Updating is done like this:
setState(() {
_fileList = newFileList;
});
i think you may try not to test on hot reload
just type in terminal : flutter run
Never mind, i accidentally disabled and then re-enabled the SlidableController.