Flutter Circular Avatar does not support Image from storage - flutter

I am looking for one widget which can handle both images(network image and storage image) in a circular shape. I have to select one image from storage if not available on network. I used many widgets and find CircleAvatar best among them. It makes circular shape if you put image in backgroundImage. It needs ImageProvider parameter. How I can to use Image.file(_file) in backgroundImage to pass it as a ImageProvider.
CircleAvatar(
radius: 80.0,
backgroundImage:
// NetworkImage("${imageNotfound}"), // NetowrkImage extends ImageProvider class, so it works
Image.file(_file), // How to convert my Image class to ImageProvider???
backgroundColor: Colors.transparent,
)
Note: My main concern is,use any single widget which have circular shape property for both(network image and storage image).

you can handle it as follows
local asset
CircleAvatar(
radius: 50.0,
backgroundImage: AssetImage("assets/images/image.jpg"),
)
network
CircleAvatar(
radius: 50.0,
backgroundImage: NetworkImage("https://images.unsplash.com/photo-1535083475219-aed59281b9aa?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60"),
)

Related

how to create multiple radial bar inside each other?

I need to make a multiple radial bar inside each other. I searched but only syncfusion_flutter_charts package had some thing like that but I it needs licenses .There is no limitation on using other flutter packages.
the chart is some thing like this multiple radial bar
The best way to do this is to use a Stack widget together with Positioned Widgets. Examples with guides are found in the added links by the Flutter team itself.
What You can do is, use Stack widget to stack the Widgets and use to Wrap those widgets in Positioned widget to Passioned them the way you want inside the Stack.
Although I should mention heavy use of stack widget will have some performance impact.
using this way you can achieve it ( this is only a example , how to do it , it is not a implementation code ) ,
write code according to the use case , that is add alignment ,positioned ,etc...
stack(children: [
CircularPercentIndicator(
radius: 50.0,
circularStrokeCap: CircularStrokeCap.round,
progressColor: Colors.purple,
.....
.....
),
CircularPercentIndicator(
radius: 100.0,
circularStrokeCap: CircularStrokeCap.round,
progressColor: Colors.red,
.....
.....
),
CircularPercentIndicator(
radius: 150.0,
circularStrokeCap: CircularStrokeCap.round,
progressColor: Colors.blue,
.....
.....
),
])
actually I found the best way.CircularPercentIndicator has a center property which takes a widget. I gave it an another CircularPercentIndicator .this way worked perfect

How do I make a child widget expand to fill a parent container inside of a stack when the child has no parameters to alter its layout?

I'm building a card game and using flame to pull the cards from a sprite sheet. The problem is that I set the width and height of the Container that holds the SpriteWidget, but the SpriteWidget expands to either the width or the height of the container, but not both. I want it to expand/stretch to be the same size as the parent container. Unfortunately, the SpriteWidget really has no parameters that could be used to change its size.
I've spent several hours scouring the internet for a solution and tried a number of widgets including FittedBox, Flex, Positioned.fill, etc., but I'm unable to achieve the desired effect. How can I make the SpriteWidget stretch to fill its parent when it has no parameters to do so?
class _PlayerHandPortraitLayout
extends WidgetView<PlayerHand, _PlayerHandController> {
#override
final state;
const _PlayerHandPortraitLayout(this.state) : super(state);
#override
Widget build(BuildContext build) {
return Stack(
children: state.displayHand().asMap().entries.map((cardItem) {
var index = cardItem.key;
var card = cardItem.value;
return Positioned(
left: index * CARD_OVERLAP_OFFSET,
child: Draggable<Container>(
childWhenDragging: Container(),
child: Container(
color: Colors.purple,
width: state.cardWidth,
height: state.cardHeight,
child: SpriteWidget(
sprite: state.spriteImages[card.suite.index][card.value.index],
),
),
feedback: Container(
color: Colors.yellow,
width: state.cardWidth,
height: state.cardHeight,
child: SpriteWidget(
sprite: state.spriteImages[card.suite.index][card.value.index],
),
),
),
);
}).toList(),
);
}
}
actually this will be not possible, SpriteWidget is designed to expand as long as it fits on the smallest dimension available on its parent, you can check on it source code here.
This is done so the Sprite will not get distorted when its parent has a different aspect ratio than the ratio of the Sprite.
If you have an use case where you would want the Sprite to get intentionally distorted, please open an issue on the Flame repository explaining the case, and we can try to take a look on it.

Flutter: How can I set a background image for Circle Avatar

I have an image in my assets folder and want to set as background for circle Avatar how should I do this?
CircleAvatar(
backgroundImage: AssetImage('assets/image.png'),
);
This will work for you.
Make sure you have added an image in the asset folder and path inside pubspec.yaml file
like
assets:
- assets/image.png
Since you already have the Image in your Assets folder.
1) Add it to your pubspec.yaml file:
assets:
- assets/yourimage.png
2) Specify the image as the backgroundImage of your CircleAvatar:
CircleAvatar(
// the circle avatar has the background image property for specifying images
backgroundImage: AssetImage('assets/yourimage.png'),
);
Something like this ?
CircleAvatar(
child: Image.network(
"https://miro.medium.com/proxy/1*ilC2Aqp5sZd1wi0CopD1Hw.png",
fit: BoxFit.scaleDown,
))
Something like this will give you a avatar with a background that will show while loading a network image
CircleAvatar(
backgroundColor: Colors.pink,
backgroundImage: AssetImage('/path/to/asset.png'),
child: Image.network('https://www.example.com/with/online.png')
);
Don't forget to put the path to the asset folder in your pubspec.yml

Flutter : set default image in Image.file

I'm currently creating Updating Image process in Flutter app.
I already succeed getting image that pass from some widget defined in View.dart to UpdateScreen widget defined in Update_screen.dart by using Network Image.
CircleAvatar(
radius: 100,
backgroundImage: NetworkImage(
'${Urls.BASE_API_IMAGE}/${widget.imageUpdate}'),
),
My question is, how to set default image using Image.file() ? , because I must use Image.file() for updating data.
Thank's
My full source code :
My Full Source Code Here
you can use this package cached_network_image as it makes it simple to set a default image.
Example
CachedNetworkImage(
imageUrl: "your url",
placeholder: (context, url) =>Your default Image Widget(),
errorWidget: (context, url, error) => new Icon(Icons.error),
),

flutter circular progress Widget

Am looking to implement a circular progress widget in flutter similar to the Jquery circular progress. The idea is when a button is clicked, as an activity happens in the background, the circular progress fills in color while a counter incrementally goes from 0-100%. I am able to do the circular fill using custom paint but am unable to display the actual % count as the color fills the circular progress. How would i do this in flutter?
Use precent_indicator library: https://pub.dev/packages/percent_indicator/install
It has good features, such as showing progress around a picture:
CircularPercentIndicator(
radius: 100.0,
lineWidth: 15.0,
progressColor: Colors.blue,
percent: 0.4,
center: const CircleAvatar(
backgroundImage: NetworkImage('https://tr.web.img4.acsta.net/c_310_420/pictures/bzp/01/61282.jpg'),
radius: 85,
),
),
),
you can use this plugin: https://pub.dartlang.org/packages/flutter_circular_chart
they have the component you need