I’m coding a flutter video game here.I have tried to test it on the web and it worked fine but when doing it on my physical device(phone) an error encountered on brick.dart file.
As a beginner I would like to get help from you guys:
import 'package:flutter/material.dart';
class MyBrick extends StatelessWidget {
final x;
final y;
MyBrick({this.x, this.y});
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment(x, y),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
color: Colors.white,
height: 20,
width: MediaQuery.of(context).size.width / 5,
),
),
);
}
}
2
Answers
The flutter
Alignment(double x, double y)
widget takes doubles. Since you are passingx
andy
to your widget without specifying their types, if you pass the valuesx = 1
andy = 3
this alignment widget will throw that error. Update your code to include your field types. this will force you to passx
andy
of appropriate types or you will get a linter error:because Alignment widget expects double values but you’re passing int values.