estoy creando una aplicación en flutter, he implementado mi sistema de medidas en base a las medidas de la pantalla del dispositivo y todo va correcto, ahora mi problema reside en que al crear mi ThemeData personalizado todo va bien hasta el momento en el que defino el tamaño de fuente a cada TextTheme. Tengo unos datos adicionales que les podria servir para encontrar este problema que me esta rompiendo la cabeza.
================= size_config.dart =================
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
class SizeConfig {
static double _screenWidth;
static double _screenHeight;
static double _blocWidth;
static double _blocHeight;
static double textMultiplier;
static double imageSizeMultiplier;
static double widthMultiplier;
static double heightMultiplier;
static bool isPortrait = true;
static bool isMobilePortrait = false;
void init(BoxConstraints constraints, Orientation orientation) {
if (orientation == Orientation.portrait) {
_screenWidth = constraints.maxWidth;
_screenHeight = constraints.maxHeight;
isPortrait = true;
if (_screenWidth < 450) isMobilePortrait = true;
} else {
_screenWidth = constraints.maxHeight;
_screenHeight = constraints.maxWidth;
isPortrait = false;
isMobilePortrait = false;
}
_blocWidth = _screenWidth / 100;
_blocHeight = _screenHeight / 100;
textMultiplier = _blocHeight;
imageSizeMultiplier = _blocWidth;
widthMultiplier = _blocWidth;
heightMultiplier = _blocHeight;
}
}
El problema esta en este archivo
================= size_config.dart =================
import 'package:flutter/material.dart';
import 'package:okrama/utilities/size_config.dart';
class AppTheme {
AppTheme._();
static const String titleFont = 'Raleway';
static const String bodyFont = 'Open Sans';
static const Color lightBackgroundColor = Colors.white;
static double largeTextSize =
(SizeConfig.textMultiplier * 3.5).roundToDouble(); // *****
static final ThemeData lightTheme = ThemeData(
fontFamily: bodyFont,
scaffoldBackgroundColor: lightBackgroundColor,
visualDensity: VisualDensity.adaptivePlatformDensity,
textTheme: lightTextTheme,
);
static final TextTheme lightTextTheme = TextTheme(
headline6: _headline6Style,
);
static final TextStyle _headline6Style = TextStyle(
fontFamily: titleFont,
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: largeTextSize, // largeTextSize == null.
);
}
Ahora explico, el problema que presenta es el siguiente
The following NoSuchMethodError was thrown building MyApp(dirty):
The method '*' was called on null.
Receiver: null
Tried calling: *(3.5)
y solo aparece cuando en la variable _headline6Style, cuando fontSize: largeTextSize, en ese momento largeTextSize es igual a null, sin embargo, si fontSize: 30, largeTextSize es igual al resultado de la operación 3.5 * SizeConfig.textMultiplier
static final TextStyle _headline6Style = TextStyle(
fontFamily: titleFont,
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: largeTextSize, // largeTextSize == null.
);
static final TextStyle _headline6Style = TextStyle(
fontFamily: titleFont,
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 30, // largeTextSize == 25.0.
);
SizeConfig.textMultiplier = 7.12