Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Migrate tools to null safety #608

Merged
merged 6 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/codeviewer/code_displayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart=2.9

import 'package:flutter/material.dart';

typedef CodeDisplayer = TextSpan Function(BuildContext context);
2 changes: 0 additions & 2 deletions lib/codeviewer/code_segments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart=2.9

import 'package:flutter/material.dart';
import 'package:gallery/codeviewer/code_style.dart';

Expand Down
24 changes: 11 additions & 13 deletions lib/codeviewer/code_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart=2.9

import 'package:flutter/material.dart';

class CodeStyle extends InheritedWidget {
const CodeStyle({
Key key,
Key? key,
this.baseStyle,
this.numberStyle,
this.commentStyle,
Expand All @@ -17,20 +15,20 @@ class CodeStyle extends InheritedWidget {
this.punctuationStyle,
this.classStyle,
this.constantStyle,
@required Widget child,
required Widget child,
}) : super(key: key, child: child);

final TextStyle baseStyle;
final TextStyle numberStyle;
final TextStyle commentStyle;
final TextStyle keywordStyle;
final TextStyle stringStyle;
final TextStyle punctuationStyle;
final TextStyle classStyle;
final TextStyle constantStyle;
final TextStyle? baseStyle;
final TextStyle? numberStyle;
final TextStyle? commentStyle;
final TextStyle? keywordStyle;
final TextStyle? stringStyle;
final TextStyle? punctuationStyle;
final TextStyle? classStyle;
final TextStyle? constantStyle;

static CodeStyle of(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<CodeStyle>();
return context.dependOnInheritedWidgetOfExactType<CodeStyle>()!;
}

@override
Expand Down
83 changes: 42 additions & 41 deletions lib/data/gallery_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart=2.9

import 'dart:async';

import 'package:flutter/material.dart';
Expand All @@ -29,30 +27,32 @@ const List<String> rtlLanguages = <String>[
// Fake locale to represent the system Locale option.
const systemLocaleOption = Locale('system');

Locale _deviceLocale;
Locale get deviceLocale => _deviceLocale;
set deviceLocale(Locale locale) {
Locale? _deviceLocale;

Locale? get deviceLocale => _deviceLocale;

set deviceLocale(Locale? locale) {
_deviceLocale ??= locale;
}

class GalleryOptions {
const GalleryOptions({
this.themeMode,
double textScaleFactor,
double? textScaleFactor,
this.customTextDirection,
Locale locale,
Locale? locale,
this.timeDilation,
this.platform,
this.isTestMode,
}) : _textScaleFactor = textScaleFactor,
this.isTestMode = false,
}) : _textScaleFactor = textScaleFactor ?? 1.0,
_locale = locale;

final ThemeMode themeMode;
final ThemeMode? themeMode;
final double _textScaleFactor;
final CustomTextDirection customTextDirection;
final Locale _locale;
final double timeDilation;
final TargetPlatform platform;
final CustomTextDirection? customTextDirection;
final Locale? _locale;
final double? timeDilation;
final TargetPlatform? platform;
final bool isTestMode; // True for integration tests.

// We use a sentinel value to indicate the system text scale option. By
Expand All @@ -68,15 +68,15 @@ class GalleryOptions {
}
}

Locale get locale => _locale ?? deviceLocale;
Locale? get locale => _locale ?? deviceLocale;

/// Returns a text direction based on the [CustomTextDirection] setting.
/// If it is based on locale and the locale cannot be determined, returns
/// null.
TextDirection resolvedTextDirection() {
TextDirection? resolvedTextDirection() {
switch (customTextDirection) {
case CustomTextDirection.localeBased:
final language = locale?.languageCode?.toLowerCase();
final language = locale?.languageCode.toLowerCase();
if (language == null) return null;
return rtlLanguages.contains(language)
? TextDirection.rtl
Expand Down Expand Up @@ -112,13 +112,13 @@ class GalleryOptions {
}

GalleryOptions copyWith({
ThemeMode themeMode,
double textScaleFactor,
CustomTextDirection customTextDirection,
Locale locale,
double timeDilation,
TargetPlatform platform,
bool isTestMode,
ThemeMode? themeMode,
double? textScaleFactor,
CustomTextDirection? customTextDirection,
Locale? locale,
double? timeDilation,
TargetPlatform? platform,
bool? isTestMode,
}) {
return GalleryOptions(
themeMode: themeMode ?? this.themeMode,
Expand Down Expand Up @@ -155,20 +155,23 @@ class GalleryOptions {

static GalleryOptions of(BuildContext context) {
final scope =
context.dependOnInheritedWidgetOfExactType<_ModelBindingScope>();
context.dependOnInheritedWidgetOfExactType<_ModelBindingScope>()!;
return scope.modelBindingState.currentModel;
}

static void update(BuildContext context, GalleryOptions newModel) {
final scope =
context.dependOnInheritedWidgetOfExactType<_ModelBindingScope>();
context.dependOnInheritedWidgetOfExactType<_ModelBindingScope>()!;
scope.modelBindingState.updateModel(newModel);
}
}

// Applies text GalleryOptions to a widget
class ApplyTextOptions extends StatelessWidget {
const ApplyTextOptions({Key key, @required this.child}) : super(key: key);
const ApplyTextOptions({
Key? key,
required this.child,
}) : super(key: key);

final Widget child;

Expand Down Expand Up @@ -198,11 +201,10 @@ class ApplyTextOptions extends StatelessWidget {

class _ModelBindingScope extends InheritedWidget {
const _ModelBindingScope({
Key key,
@required this.modelBindingState,
Widget child,
}) : assert(modelBindingState != null),
super(key: key, child: child);
Key? key,
required this.modelBindingState,
required Widget child,
}) : super(key: key, child: child);

final _ModelBindingState modelBindingState;

Expand All @@ -212,11 +214,10 @@ class _ModelBindingScope extends InheritedWidget {

class ModelBinding extends StatefulWidget {
const ModelBinding({
Key key,
Key? key,
this.initialModel = const GalleryOptions(),
this.child,
}) : assert(initialModel != null),
super(key: key);
required this.child,
}) : super(key: key);

final GalleryOptions initialModel;
final Widget child;
Expand All @@ -226,8 +227,8 @@ class ModelBinding extends StatefulWidget {
}

class _ModelBindingState extends State<ModelBinding> {
GalleryOptions currentModel;
Timer _timeDilationTimer;
late GalleryOptions currentModel;
Timer? _timeDilationTimer;

@override
void initState() {
Expand All @@ -246,15 +247,15 @@ class _ModelBindingState extends State<ModelBinding> {
if (currentModel.timeDilation != newModel.timeDilation) {
_timeDilationTimer?.cancel();
_timeDilationTimer = null;
if (newModel.timeDilation > 1) {
if (newModel.timeDilation! > 1) {
// We delay the time dilation change long enough that the user can see
// that UI has started reacting and then we slam on the brakes so that
// they see that the time is in fact now dilated.
_timeDilationTimer = Timer(const Duration(milliseconds: 150), () {
timeDilation = newModel.timeDilation;
timeDilation = newModel.timeDilation!;
});
} else {
timeDilation = newModel.timeDilation;
timeDilation = newModel.timeDilation!;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions lib/layout/text_scale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart=2.9

import 'dart:math';

import 'package:flutter/material.dart';
Expand Down
8 changes: 8 additions & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ list(APPEND FLUTTER_PLUGIN_LIST
url_launcher_linux
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
)

set(PLUGIN_BUNDLED_LIBRARIES)

foreach(plugin ${FLUTTER_PLUGIN_LIST})
Expand All @@ -14,3 +17,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)

foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ packages:
name: coverage
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
version: "1.1.0"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -735,7 +735,7 @@ packages:
name: vm_service
url: "https://pub.dartlang.org"
source: hosted
version: "7.5.0"
version: "8.1.0"
watcher:
dependency: transitive
description:
Expand Down
2 changes: 0 additions & 2 deletions tool/codeviewer_cli/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart=2.9

import 'dart:io';

import 'package:args/args.dart';
Expand Down
Loading