ofNullable static method

TDThemeData? ofNullable([
  1. BuildContext? context
])

获取主题数据,取不到则可空 传了context,则获取最近的主题,取不到或未传context则返回null,

Implementation

static TDThemeData? ofNullable([BuildContext? context]) {
  if (context != null) {
    // 如果传了context,则从其中获取最近主题
    return Theme.of(context).extensions[TDThemeData] as TDThemeData?;
  } else {
    // 如果context为null,则返回null
    return null;
  }
}