width, height가 아니라 화면 비율에 맞게 변화할 수 있는 위젯
The argument type 'TextStyle?' can't be assigned to the parameter type 'Color?'
Methods can't be invoked in constant expressions
상수 안에서는 메서드를 호출할 수 없다는 뜻이다.
color: Theme.of(context).textTheme.headlineLarge?.color,
나는 위 예제에서 발생했었는데 위쪽에서 자동으로 붙었던 const때문에 발생했던 에러였다.
쉬운 에러였는데 실수 때문에 생긴 다른 에러와 겹치면서 해결이 너무 지연됐다...
Theme.of(context)~~로 불러온 메서드는 const에서는 사용할 수 없다.
import 'package:flutter/material.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
body: Column(
children: [
Flexible(
flex: 1,
child: Container(
alignment: Alignment.bottomCenter,
child: Text(
"25:00",
style: TextStyle(
color: Theme.of(context).cardColor,
fontSize: 90,
fontWeight: FontWeight.w600,
),
),
),
),
Flexible(
flex: 3,
child: Center(
child: IconButton(
iconSize: 120,
color: Theme.of(context).cardColor,
onPressed: () {},
icon: const Icon(Icons.play_circle_outline),
),
),
),
Flexible(
flex: 1,
child: Row(
children: [
Expanded(
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Pomodoros',
style: TextStyle(
fontSize: 20,
color: Theme.of(context)
.textTheme
.headlineLarge!
.color,
fontWeight: FontWeight.w600,
),
),
Text(
'0',
style: TextStyle(
fontSize: 58,
color: Theme.of(context)
.textTheme
.headlineLarge!
.color,
fontWeight: FontWeight.w600,
),
)
],
),
),
),
],
),
)
],
),
);
}
}