Enable unreachable_from_main lint - it is stable now!!1 (#129854)

PLUS: clean-up of all the unreachable stuff.
This commit is contained in:
Michael Goderbauer
2023-07-05 17:09:01 -07:00
committed by GitHub
parent 99cb18b1a8
commit 55b6f049a6
45 changed files with 66 additions and 419 deletions

View File

@@ -12,9 +12,10 @@ const int _kNumWarmUp = 100;
class Data {
Data(this.value);
Map<String, dynamic> toJson() => <String, dynamic>{ 'value': value };
final int value;
@override
String toString() => 'Data($value)';
}
List<Data> test(int length) {

View File

@@ -5,7 +5,6 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation;
void main() {
runApp(
@@ -31,12 +30,6 @@ class PlatformViewAppState extends State<PlatformViewApp> {
home: const PlatformViewLayout(),
);
}
void toggleAnimationSpeed() {
setState(() {
timeDilation = (timeDilation != 1.0) ? 1.0 : 5.0;
});
}
}
class PlatformViewLayout extends StatelessWidget {

View File

@@ -5,7 +5,6 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation;
void main() {
runApp(
@@ -31,12 +30,6 @@ class PlatformViewAppState extends State<PlatformViewApp> {
home: const PlatformViewLayout(),
);
}
void toggleAnimationSpeed() {
setState(() {
timeDilation = (timeDilation != 1.0) ? 1.0 : 5.0;
});
}
}
class PlatformViewLayout extends StatelessWidget {

View File

@@ -5,7 +5,6 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation;
import 'package:flutter_driver/driver_extension.dart';
import 'android_platform_view.dart';
@@ -35,12 +34,6 @@ class PlatformViewAppState extends State<PlatformViewApp> {
home: const PlatformViewLayout(),
);
}
void toggleAnimationSpeed() {
setState(() {
timeDilation = (timeDilation != 1.0) ? 1.0 : 5.0;
});
}
}
class PlatformViewLayout extends StatelessWidget {

View File

@@ -46,11 +46,6 @@ void main() {
/// It keeps a list of history entries and event listeners in memory and
/// manipulates them in order to achieve the desired functionality.
class TestUrlStrategy extends UrlStrategy {
/// Creates a instance of [TestUrlStrategy] with an empty string as the
/// path.
factory TestUrlStrategy() =>
TestUrlStrategy.fromEntry(const TestHistoryEntry(null, null, ''));
/// Creates an instance of [TestUrlStrategy] and populates it with a list
/// that has [initialEntry] as the only item.
TestUrlStrategy.fromEntry(TestHistoryEntry initialEntry)
@@ -64,8 +59,6 @@ class TestUrlStrategy extends UrlStrategy {
dynamic getState() => currentEntry.state;
int _currentEntryIndex;
int get currentEntryIndex => _currentEntryIndex;
final List<TestHistoryEntry> history;
TestHistoryEntry get currentEntry {
@@ -105,16 +98,6 @@ class TestUrlStrategy extends UrlStrategy {
currentEntry = TestHistoryEntry(state, title, url);
}
/// This simulates the case where a user types in a url manually. It causes
/// a new state to be pushed, and all event listeners will be invoked.
Future<void> simulateUserTypingUrl(String url) {
assert(withinAppHistory);
return _nextEventLoop(() {
pushState(null, '', url);
_firePopStateEvent();
});
}
@override
Future<void> go(int count) {
assert(withinAppHistory);

View File

@@ -56,13 +56,6 @@ class Memento extends Object with Diagnosticable {
/// An [ActionDispatcher] subclass that manages the invocation of undoable
/// actions.
class UndoableActionDispatcher extends ActionDispatcher implements Listenable {
/// Constructs a new [UndoableActionDispatcher].
///
/// The [maxUndoLevels] argument must not be null.
UndoableActionDispatcher({
int maxUndoLevels = _defaultMaxUndoLevels,
}) : _maxUndoLevels = maxUndoLevels;
// A stack of actions that have been performed. The most recent action
// performed is at the end of the list.
final DoubleLinkedQueue<Memento> _completedActions = DoubleLinkedQueue<Memento>();
@@ -70,19 +63,12 @@ class UndoableActionDispatcher extends ActionDispatcher implements Listenable {
// at the end of the list.
final List<Memento> _undoneActions = <Memento>[];
static const int _defaultMaxUndoLevels = 1000;
/// The maximum number of undo levels allowed.
///
/// If this value is set to a value smaller than the number of completed
/// actions, then the stack of completed actions is truncated to only include
/// the last [maxUndoLevels] actions.
int get maxUndoLevels => _maxUndoLevels;
int _maxUndoLevels;
set maxUndoLevels(int value) {
_maxUndoLevels = value;
_pruneActions();
}
int get maxUndoLevels => 1000;
final Set<VoidCallback> _listeners = <VoidCallback>{};
@@ -121,7 +107,7 @@ class UndoableActionDispatcher extends ActionDispatcher implements Listenable {
// Enforces undo level limit.
void _pruneActions() {
while (_completedActions.length > _maxUndoLevels) {
while (_completedActions.length > maxUndoLevels) {
_completedActions.removeFirst();
}
}
@@ -237,26 +223,12 @@ class RedoAction extends Action<RedoIntent> {
}
/// An action that can be undone.
abstract class UndoableAction<T extends Intent> extends Action<T> {
/// The [Intent] this action was originally invoked with.
Intent? get invocationIntent => _invocationTag;
Intent? _invocationTag;
@protected
set invocationIntent(Intent? value) => _invocationTag = value;
@override
@mustCallSuper
void invoke(T intent) {
invocationIntent = intent;
}
}
abstract class UndoableAction<T extends Intent> extends Action<T> { }
class UndoableFocusActionBase<T extends Intent> extends UndoableAction<T> {
@override
@mustCallSuper
Memento invoke(T intent) {
super.invoke(intent);
final FocusNode? previousFocus = primaryFocus;
return Memento(name: previousFocus!.debugLabel!, undo: () {
previousFocus.requestFocus();
@@ -295,8 +267,6 @@ class UndoablePreviousFocusAction extends UndoableFocusActionBase<PreviousFocusI
}
class UndoableDirectionalFocusAction extends UndoableFocusActionBase<DirectionalFocusIntent> {
TraversalDirection? direction;
@override
Memento invoke(DirectionalFocusIntent intent) {
final Memento memento = super.invoke(intent);

View File

@@ -30,15 +30,13 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyHomePage(title: _title),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
@@ -92,12 +90,6 @@ class OptionModel extends ChangeNotifier {
bool get longText => _longText;
bool _longText = false;
set longText(bool longText) {
if (longText != _longText) {
_longText = longText;
notifyListeners();
}
}
void reset() {
final OptionModel defaultModel = OptionModel();

View File

@@ -778,9 +778,4 @@ enum TestMenu {
final String acceleratorLabel;
// Strip the accelerator markers.
String get label => MenuAcceleratorLabel.stripAcceleratorMarkers(acceleratorLabel);
int get acceleratorIndex {
int index = -1;
MenuAcceleratorLabel.stripAcceleratorMarkers(acceleratorLabel, setIndex: (int i) => index = i);
return index;
}
}

View File

@@ -81,13 +81,12 @@ Future<void> runSmokeTests({
// A class to hold information related to an example, used to generate names
// from for the tests.
class ExampleInfo {
ExampleInfo(this.file, Directory examplesLibDir)
ExampleInfo(File file, Directory examplesLibDir)
: importPath = _getImportPath(file, examplesLibDir),
importName = '' {
importName = importPath.replaceAll(RegExp(r'\.dart$'), '').replaceAll(RegExp(r'\W'), '_');
}
final File file;
final String importPath;
String importName;