Flexible(
fit: FlexFit.tight,
child: OpenContainer(
closedShape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(20))),
transitionDuration: const Duration(milliseconds: 1000),
openBuilder: (context, _) {
return MealDetailScreen(
meal: meal,
);
},
closedBuilder: (context, openContainer) {
return GestureDetector(
onTap: openContainer,
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(20)),
child: Image.asset(
meal.imagePath,
width: 150,
fit: BoxFit.fill,
),
),
);
},
),
),
The method 'OpenContainer' isn't defined for the type '_MealCard'. (Documentation) Try correcting the name to the name of an existing method, or defining a method named 'OpenContainer'.
When i try use OpenContainer i am encountering this error. I dont have animations.dart in my flutter version.do i need this dart ? Or is there another source of the problem? What should I do to write the code in the correct format? Thanks to everyone who has helped/tryed to help so far!
Yes, OpenContainer is part of the animations package and if you want to use it, you must install it.
Related
Im trying to make a flutter app for HR and for my employee's section I need to have it so that their initials are shown if a profile picture is unavailable is there a widget which allows me to do this?
Below is an example of what im trying to achieve
You can try it with CachedNetworkImage
CachedNetworkImage(
imageUrl: "http://myimage...",
placeholder: (context, url) => new CircularProgressIndicator(),
errorWidget: (context, url, error) => new Text("my initials here"),
),
You need to Do Something Like This, but first Need to check for Image thats depends on how you are managing data and then
_isImageAvailable ? ProfileImage() : Text(Name)
Container(
height: 100.0,
width: 100.0,
color: Colors.grey,
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: hasImage
? Image.network(
imageUrl,
fit: BoxFit.contain,
)
: Center(
child: Text('$nameInitial'),
),
),
)
how to make the picture zoomable when the photo is clicked, here's the code I made to display the image
Column(
children: [
image11 != null
? Image.file(
image11,
width: 50,
height: 50,
fit: BoxFit.cover,
)
: Text(" Bagian Belakang"),
Container(
margin: const EdgeInsets.fromLTRB(14, 5, 0, 0),
child: RaisedButton(
padding: EdgeInsets.all(10),
onPressed: () {
pickImage11(ImageSource.camera);
},
child: Icon(Icons.camera),
),
),
],
),
Taking inspiration from this answer Hero animation with an AlertDialog
You can use a Hero widget combined with a PageRouteBuilder to imitate a zoom feature:
Navigator.of(context).push(
PageRouteBuilder(
opaque: false,
barrierDismissible:true,
pageBuilder: (BuildContext context, _, __) {
return Hero(
tag: "zoom",
child: Image.file(...),
);
}
)
);
EDIT: I found barrier dismissable not working and found the solution here: Flutter SizeTransition and PageRouteBuilder not working
You will have to wrap the Hero widget with a defined width and height to get the optimum zoom level.
Widget _buildAnimatedLogo() {
return ControlledAnimation( //<-- The method 'ControlledAnimation' isn't defined for the type 'LogoState'
duration: widget.logoAnimationTween.duration,
tween: widget.logoAnimationTween,
builder: (context, animation) {
return Transform.rotate(
angle: animation["rotation"],
child: Padding(
padding: const EdgeInsets.only(
bottom: 10,
),
child: Container(
width: animation["size"],
height: animation["size"],
child: Image.asset(
"assets/images/logo.png",
fit: BoxFit.fitHeight,
),
),
),
);
},
);
}
I am using simple_animations: ^3.0.1, not sure if I am using the wrong class "ControlledAnimation"
You migrated to a newer version.
Change that with ControlledAnimation -> PlayAnimation.
Check the official example
It looks like the parentheses and braces in the code you pasted are not properly closed. Note that your _buildAnimatedLogo method has no closing squirly brace.
If that is not the issue, it looks like the compiler mixed methods and widgets. It thinks ControlledAnimation is a method, when it looks like it should be a widget. Try setting a prefix to your simple_animations import statement, like this:
import '.../simple_animations.dart' as simple_animations;
then try to call simple_animations.ControlledAnimation instead of ControlledAnimation directly. Try to see if that makes the task easy for the compiler.
I've just implemented the Flutter package cached_network_image and I wonder how I can preload images so they're available later in an instant. I retrieve all image-urls that will be used later from the our server.
I've defined my custom cache manager getter:
class LocalCacheManager {
static const key = 'customCacheKey';
static CacheManager instance = CacheManager(
Config(
key,
stalePeriod: const Duration(days: 14),
maxNrOfCacheObjects: 200,
repo: JsonCacheInfoRepository(databaseName: key),
fileSystem: LocalCacheFileSystem(key),
fileService: HttpFileService(),
),
);
}
Here's how I currently try to preload the image:
LocalCacheManager.instance.downloadFile(MY_IMAGE_URL)),
And here's how I create the widget:
child: CachedNetworkImage(imageUrl: MY_IMAGE_URL, cacheManager: LocalCacheManager.instance),
But I can clearly see that files are always cached again as soon as I create the CachedNetworkImage.
You can use Flutter Cache Manager like this
DefaultCacheManager().downloadFile(MY_IMAGE_URL).then((_) {});
Later, just use your cached image like this
child: CachedNetworkImage(imageUrl: MY_IMAGE_URL,),
Simplest and workable way is to use precacheImage (flutter build-in function) with CachedNetworkImageProvider:
Image image = Image(
image: CachedNetworkImageProvider(/* url */),
fit: BoxFit.cover,
);
precacheImage(image.image, context);
return Padding(
padding: EdgeInsets.symmetric(horizontal: 16.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: image,
),
);
cached_network_image: ^2.0.0
CachedNetworkImage(
imageUrl: yoururl,
errorWidget: (context, url, error) => Text("error"),
imageBuilder: (context, imageProvider) => CircleAvatar(
radius: 120,
backgroundImage: imageProvider,
),
placeholder: (context, url) => CircularProgressIndicator(
backgroundColor: primary,
),
),
How can I assign an image dynamically in flutter ? For example:
final topContent = Stack(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 10.0),
height: MediaQuery.of(context).size.height * 0.5,
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage(lesson.imagePath),
fit: BoxFit.cover,
),
)),
Container(
height: MediaQuery.of(context).size.height * 0.5,
padding: EdgeInsets.all(40.0),
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(color: Color.fromRGBO(58, 66, 86, .9)),
child: SingleChildScrollView(
controller: _scrollController,
child: Center(
child: topContentText,
),
),
),
Positioned(
left: 8.0,
top: 60.0,
child: InkWell(
onTap: () {
Navigator.pop(context);
},
child: Icon(Icons.arrow_back, color: Colors.white),
),
)
],
);
Now the image at the start lesson.imagePath is what I want to change dynamically. I tried to use setState() but it gives me an error:
The expression here is a type of void and cannot be used
image: setState ((){
if (someCondition) {
return new AssetImage(lesson.imagePath);
}
}),
Your setState call is wrong! The most simple way is make your image as state of your widget and update this image inside a setState call. setState method does not returns nothing it just rebuilds your widget.
In your _WidgetState class you declare as member:
AssetImage _imageToShow;
You can provider a initial image inside initState method.
#override
initState(){
_imageToShow = AssetImage('youAssetImage');
}
Your Container widget should be declared as:
Container(
padding: EdgeInsets.only(left: 10.0),
height: MediaQuery.of(context).size.height * 0.5,
decoration: new BoxDecoration(
image: new DecorationImage(
image: _imageToShow,
fit: BoxFit.cover,
),
)),
),
And to update your image with setState call you just need:
void updateImage() {
setState ((){
if (someCondition) {
_imageToShow = new AssetImage(lesson.imagePath);
}
});
}
But remember that something has to call updateImage method.
The above solution can work also you can set an array of names and you can set the same image name in the assets folder and you can dynamically select the image where you want to use.
suppose in your case you have a list of lessons.
var lesson = ['a','b','c'];
In assets, folder give the same name to the images. (Don't forget to update the pubspec.yaml file)
Then in the AssetImage you can give the path which can be chosen dynamically.
image:AssetImage('assets/${lesson[index]}.jpg')
Remember to give the same name to the image like here a,b and c to the image.
Also the same extension to be given like here .jpg
image:AssetImage('assets/${lesson[index]}.jpg')