Unable to change the width after "Transform.scale"?
In the following sample code, the red Container, do not change width after setting fitWidth(width of container) when pressing the floatingbutton.
Only if it is les than MediaQuery.of(context).size.width.
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: MyStatefulWidget(),
);
}
}
class MyStatefulWidget extends StatefulWidget {
MyStatefulWidget({Key key}) : super(key: key);
@override
_MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}
// State
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
Matrix4 matrix = Matrix4.identity();
double fitWidth;
@override
void initState() {
fitWidth = 0;
super.initState();
}
double getSizeWidth(BuildContext context) {
if (fitWidth != 0) {
return fitWidth;
} else {
return MediaQuery.of(context).size.width;
}
}
Widget build(BuildContext context) {
var sizWidth = getSizeWidth(context);
print(sizWidth);
return Scaffold(
appBar: AppBar(
title: const Text('Sample Code'),
),
body: Transform.scale(
scale: 0.5,
child: Container(
color: Colors.red,
width: sizWidth,
height: 400,
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
fitWidth = 800;
});
// Add your onPressed code here!
},
backgroundColor: Colors.green,
));
}
}