Expected to find ')' in Positioned in flutter - flutter

how do i fix this
[Text](https://stackoverflow.com/fluttererror.png[Expected to find ')'][1])
),Positioned(
top: 504,
left: 320,
child: SvgPicture.asset('assets/images/ellipse2.svg', semanticsLabel: 'ellipse2'
);//line 59 error
),Positioned(
top: 782,
left: -77,
child: SvgPicture.asset('assets/images/ellipse3.svg',semanticsLabel: 'ellipse3'
);//line 64 error
what i've tried is adding ')' to line 59 and 64, putting const on the widget still the same error

The issue here seems simply that you put the semicolon at the end of your SvgPicture, you should replace those with a comma!
),Positioned(
top: 504,
left: 320,
child: SvgPicture.asset('assets/images/ellipse2.svg', semanticsLabel: 'ellipse2'
), //Comma goes here
),Positioned(
top: 782,
left: -77,
child: SvgPicture.asset('assets/images/ellipse3.svg',semanticsLabel: 'ellipse3'
), //Comma goes here

Change
),Positioned(
top: 504,
left: 320,
child: SvgPicture.asset('assets/images/ellipse2.svg', semanticsLabel: 'ellipse2'
);
),Positioned(
top: 782,
left: -77,
child: SvgPicture.asset('assets/images/ellipse3.svg',semanticsLabel: 'ellipse3'
);
to
),Positioned(
top: 504,
left: 320,
child: SvgPicture.asset('assets/images/ellipse2.svg', semanticsLabel: 'ellipse2'
),
),Positioned(
top: 782,
left: -77,
child: SvgPicture.asset('assets/images/ellipse3.svg',semanticsLabel: 'ellipse3'
),

Related

Animation in Flutter: How to resize a Stack?

What's the right way to animate a change in size of a Stack widget?
The first idea was to wrap the Stack with a SizeTransition:
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SizeTransition(
sizeFactor: _height, // Just a Tween<double>(begin: 200, end: 400)
axis: Axis.vertical,
axisAlignment: -1,
child: Stack(
children: [
Positioned(
bottom: 10,
left: 10,
child: Container(width: 50, height: 50, color: Colors.blue),
),
Positioned(
top: 10,
right: 10,
child: Container(width: 50, height: 50, color: Colors.green),
),
],
),
),
],
);
}
But running the snippet causes the following error:
'package:flutter/src/rendering/stack.dart': Failed assertion: line 588 pos 12: 'size.isFinite': is not true.
So, apparently, that's not the right way to do it. Questions now is: How do you animate resizing of a Stack?
Wrapping the Stack with a SizedBox would fix the error message, but then, how do you get the size from SizedTransition to set the proper size of a SizedBox?
You can use AnimatedContainer as parent of Stack widget by providing height or width one you like to change over time.
AnimatedContainer(
color: Colors.purple,
duration: const Duration(milliseconds: 200),
height: height,
child: Stack(
children: [
Positioned(
bottom: 10,
left: 10,
child: Container(width: 50, height: 50, color: Colors.blue),
),
Positioned(
top: 10,
right: 10,
child: Container(width: 50, height: 50, color: Colors.green),
),
],
),
),

How to add search results 'no results found' text?

I would like to show a text when there are no results. I know how to get that text and make sure it is dynamic, but I do not know how I can add it to the SearchResultCell (because that is where the results are being shown when there are items).
child: Container(
margin: EdgeInsets.only(left: 25, right: 25, bottom: 15),
height: 50,
child: SearchResultCell(
search: this._search[index],
))
I can't use children, because container does not allow it + I have to put the text in the SearchResultCell, but don't know how.
You can use children by doing this,
Container(
margin: EdgeInsets.only(left: 25, right: 25, bottom: 15),
height: 50,
child: Column(
children:
SearchResultCell(
search: this._search[index],
),
//another widget
)
)

How do I add Opacity to my eclipse container in flutter as shown below?

With Opacity
Without Opacity
I want to convert my container to opacity like shown above. How to do it?
Here is my code for the container:
Positioned(
bottom: 0,
child: Arc(
arcType: ArcType.CONVEX,
edge: Edge.TOP,
height: 60.0,
child: Opacity(
opacity: 1,
child: new Container(
height: 140,
width: MediaQuery.of(context).size.width,
color: Colors.white.withOpacity(0.8),
),
),
),
),
You can just wrap your Container with BackdropFilter widget so BackdropFilter widget takes one child and filter value. here u can get more info about BackdropFilter Widget
and if you wanna get wrapped your container with BackdropFilter widget you should be do this:
Positioned(
bottom: 0,
child: Arc(
arcType: ArcType.CONVEX,
edge: Edge.TOP,
height: 60.0,
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 3, sigmaY: 5),
child: Container(
height: 140,
width: MediaQuery.of(context).size.width,
color: Colors. black.withOpacity(0),
),
),
),
),
what you need is backdropfilter:
Positioned(
bottom: 0,
child: Arc(
arcType: ArcType.CONVEX,
edge: Edge.TOP,
height: 60.0,
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Container(
height: 140,
width: MediaQuery.of(context).size.width,
color: Colors. black.withOpacity(0),
),
),
),
),
Add the line
const Color(0xFF0E3311).withOpacity(0.5)
Container(
decoration: new BoxDecoration(
color: const Color(0xFF0E3311).withOpacity(0.5),
),
),

Flutter Container on top of rows

I made a bunch of rows. Now I want a Container on top of these rows. How can I do this. I tried it with the stack widget ,but it just stacked everything on top of each other and I had no control over the positioning.
How can I draw a Container on top of a bunch of rows.
Thank you for your help.
You can check the below code, though your asking is little bit confusing. You need to use Positioned and set some value at top and left.
Scaffold(
body: Stack(
children: [
Positioned(
top:0 ,
left: 0,
child: Container(
height: 100,
width: 100,
color: Colors.red,
),
),
Positioned(
top:100 ,
left: 0,
child: Container(
height: 100,
width: 100,
color: Colors.red,
child: Row(),
),
),
Positioned(
top:200 ,
left: 0,
child: Container(
height: 100,
width: 100,
color: Colors.red,
child: Row(),
),
),
Positioned(
top:300 ,
left: 0,
child: Container(
height: 100,
width: 100,
color: Colors.red,
child: Row(),
),
),
],
),
)

Flutter UI breaks when "smallest width" is changed in developer options

I am new into flutter programming. I have been working on a certain UI as shown below.
If I attempt to change the "smallest width" option in the developer options and set to some other value than the default, the whole UI breaks as shown.
I must add that the middle area which got completely broken was a stack widget.
#override
Widget build(BuildContext context) {
return Consumer<SinglePlayerGameState>(
builder: (context, gameState, child) => Expanded(
flex: 48,
child: Container(
color: gameState.getGameColor(),
child: Center(
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
Positioned(
child: Transform.rotate(
angle: 45,
child: UNOcard(UNOcardData(CardTypes.BACK)),
),
top: -30,
left: 90,
),
Positioned(
child: Transform.rotate(
angle: 65,
child: UNOcard(UNOcardData(CardTypes.BACK)),
),
top: 20,
left: 50,
),
Positioned(
child: Transform.rotate(
angle: 180,
child: UNOcard(UNOcardData(CardTypes.BACK)),
),
top: 100,
left: 65,
),
Positioned(
child: Transform.rotate(
angle: 45,
child: UNOcard(UNOcardData(CardTypes.BACK)),
),
top: 10,
right: 10,
),
Positioned(
child: Transform.rotate(
angle: 65,
child: UNOcard(UNOcardData(CardTypes.BACK)),
),
top: 120,
right: 50,
),
Positioned(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.black),
child: Text(
"${gameState.playingCards.length}",
style: TextStyle(
fontSize: 20,
fontFamily: 'Frijole',
color: Colors.white),
),
padding: EdgeInsets.all(7),
),
top: 10,
left: 10,
),
Positioned(
child: SizedBox(
child: Center(
child: FlatButton(
onPressed: () {
gameState.nextTurn();
},
child: Icon(
FontAwesomeIcons.undoAlt,
size: 25,
),
color: Colors.white,
)),
height: 35,
width: 60,
),
bottom: 10,
left: 10,
),
Positioned(
child: DragTarget<UNOcardData>(
onWillAccept: (UNOcardData data) {
var res = isValidMove(
data, gameState.onGoingCards.last, gameState);
if(res){
print(res);
return true;
}else{
vibrate();
return false;
}
},
onAccept: (UNOcardData data) {
print(data);
performAction(data, gameState);
},
builder: (context, candidateData, rejectedData) =>
Transform.rotate(
angle: 0,
child: gameState.onGoingCards.last,
),
),
top: 60,
right: 100,
),
],
),
),
),
),
);
}
}
Like we use units like "vmin , vmax , vh " etc in html/css for responsive texts and sizes, what are the alternatives in flutter ? How do we responsive apps in flutter exactly ? I am not talking about scaling to other screen sizes, but to slightly different resolutions and logical pixel densities.
Thanks for your time.
That's because you are using margins from the edges with
Positioned(
child: Transform.rotate(
angle: 180,
child: UNOcard(UNOcardData(CardTypes.BACK)),
),
top: 100,
left: 65,
),
This top means that it's going to position itself 100 units from the top. What you actually want is some percentage offset from the center. You can do it like this:
Positioned.fill(
child: Align(
// (0, 0) is the center, (1, 1) is right bottom, (-1, -1) is left top and so on
alignment: Alignment(0.25, 0.25),
child: YOUR_WIDGET
)
);
For more responsive UI you can get screen_sizes with MediaQuery.of(context) or use a package like flutter_screenutil to scale your UI according to a sample, like for example 1080x1920 screen.