i want to put a grid over an svg but when the dimensions of the screen change my image go to the bottom and my grid to the top how can i do to maintain the grid inside the svg when the screen change and how can i fix the grid vertically and horizontally
that’s the code
void main() {
runApp(RunMyApp());
}
class RunMyApp extends StatelessWidget {
const RunMyApp({Key? key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(primarySwatch: Colors.green),
home: Scaffold(
appBar: AppBar(title: Text('Grid with Right Bar')),
body: Row(
children: [
Expanded(
child: InteractiveViewer(
boundaryMargin: EdgeInsets.all(50.0),
minScale: 0.1,
maxScale: 6.0,
child: Stack(
alignment: Alignment.center,
children: [
SvgPicture.asset(
'assets/scavi.svg',
semanticsLabel: 'My SVG Image',
),
Positioned.fill(
child: bigGrid(),
),
],
),
),
),
],
),
),
);
}
}
GridView bigGrid() {
return GridView.count(
physics: NeverScrollableScrollPhysics(),
crossAxisCount: 20,
children: List.generate(
20,
(index) {
return Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
),
);
},
),
);
}
2
Answers
Positioned
widget has some other properties. Such astop
,right
,left
,bottom
, etc. UseMediaQuery
to set the right position of your widget based on screen size.//Updated new answer. use
AspectRatio
widget to maintain the aspect ratio of its child to fit it within the available space.Have you considered changing the
crossAxisCount
and thecount
values ofGrid.count
andList.generate
respectively using MediaQuery? Try the following: