everyone.
(A)The code below stretches the text as much as possible vertically (and horizontally) within the range of 300*300.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Animated Icons',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar:AppBar(),
body:
Container(
color:Colors.blue,
width:300.0,
height:300.0,
child:
FittedBox(
fit: BoxFit.fill,
child: Text(
'Some Example Text.',
style: TextStyle(
fontSize: 20.0,
),
),
),
),
);
}
}
(B)On the other hand, the code below does not stretch the text.
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar:AppBar(),
body:
// Container(
// color:Colors.blue,
// width:300.0,
// height:300.0,
// child:
FittedBox(
fit: BoxFit.fill,
child: Text(
'Some Example Text.',
style: TextStyle(
fontSize: 20.0,
),
),
),
// ),
);
}
}
Why is this?
My understanding at this point is that in code (B), the constraint passed from the parent to the FittedBox is the screen size (minus the size of the AppBar), so I expected the text to be stretched across the entire screen except for the AppBar.
However, the actual result is very different. Why is that? Are there any points to consider that I'm missing?
Even if I ask "Why?", I actually got such results, so if I just use the framework, I have no choice but to accept it.