I believe it is related to the origin parameter but I didn't manage to get it working:
Here is my code (and its dart pad right there: https://dartpad.dev/?id=1ef23afddb2d4f73744941b1d5493047):
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Scale the scene to the red line'),
);
}
}
class MyHomePage extends StatefulWidget {
final String title;
const MyHomePage({
Key? key,
required this.title,
}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final double originRatio = 1/4;
Widget scene({required Size size, required Color color}) {
return Stack(children:[
Positioned(left:0,top:0, child: SizedBox(
width: size.width,
height: size.height, child: Container(color: color))
),
Positioned(left:size.width*originRatio,top:0, child: SizedBox(
width: 10,
height: size.height, child: Container(color: Colors.red))
),
]);
}
@override
Widget build(BuildContext context) {
const sceneSize = Size(400,200);
const scale = 0.8;
final origin = Offset(-sceneSize.width*originRatio*scale,0);
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Stack(children: [
// == Scaled
Transform.scale(
scale: scale,
origin: origin,
child: scene(size: sceneSize, color: Colors.brown)
),
// == Not scaled
scene(size: sceneSize, color: Colors.amber)
])
);
}
}
