'The element type 'VxAnimatedBox' can't be assigned to the list type 'Widget'
Here I'm trying to use VxAnimatedbox under scaffold but it's showing error
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: Drawer(),
body:Stack(children: [
VxAnimatedBox().size(context.screenWidth, context.screenHeight)
.withGradient(LinearGradient(
colors: AIColors.primaryColor1,
))
],)
);
}
}
These are the 2 errors its showing
The element type 'VxAnimatedBox' can't be assigned to the list type 'Widget'.
The argument type 'Color' can't be assigned to the parameter type 'List<Color>'.
Solution 1:[1]
The error it's telling you that the LinearGradient object is expecting a List, but you are passing just ONE Color.
You can fix it by putting that one color inside a List (and, if you want, add more colors to your liking)
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: Drawer(),
body:Stack(children: [
VxAnimatedBox().size(context.screenWidth, context.screenHeight)
.withGradient(LinearGradient(
colors: [AIColors.primaryColor1],
))
],)
);
}
}
Solution 2:[2]
After you have written
VxAnimatedBox().size(context.screenWidth, context.screenHeight), make sure you add .make(), it worked for me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dani3le_ |
| Solution 2 | siddharth |
