Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the `engine` subdirectory and enforces that these files stay formatted with a presubmit check. **Reviewers:** Please carefully review all the commits except for the one titled "formatted". The "formatted" commit was auto-generated by running `dev/tools/format.sh -a -f`. The other commits were hand-crafted to prepare the repo for the formatting change. I recommend reviewing the commits one-by-one via the "Commits" tab and avoiding Github's "Files changed" tab as it will likely slow down your browser because of the size of this PR. --------- Co-authored-by: Kate Lovett <katelovett@google.com> Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8e0993eda8
commit
5491c8c146
@@ -16,7 +16,7 @@ typedef OnResultListener = void Function(String result);
|
||||
// The choice of JSON parsing here is meant as an example that might surface
|
||||
// in real-world applications.
|
||||
class Calculator {
|
||||
Calculator({ required this.onProgressListener, required this.onResultListener, String? data })
|
||||
Calculator({required this.onProgressListener, required this.onResultListener, String? data})
|
||||
: _data = _replicateJson(data, 10000);
|
||||
|
||||
final OnProgressListener onProgressListener;
|
||||
@@ -31,14 +31,12 @@ class Calculator {
|
||||
// Run the computation associated with this Calculator.
|
||||
void run() {
|
||||
int i = 0;
|
||||
final JsonDecoder decoder = JsonDecoder(
|
||||
(dynamic key, dynamic value) {
|
||||
if (key is int && i++ % _NOTIFY_INTERVAL == 0) {
|
||||
onProgressListener(i.toDouble(), _NUM_ITEMS.toDouble());
|
||||
}
|
||||
return value;
|
||||
},
|
||||
);
|
||||
final JsonDecoder decoder = JsonDecoder((dynamic key, dynamic value) {
|
||||
if (key is int && i++ % _NOTIFY_INTERVAL == 0) {
|
||||
onProgressListener(i.toDouble(), _NUM_ITEMS.toDouble());
|
||||
}
|
||||
return value;
|
||||
});
|
||||
try {
|
||||
final List<dynamic> result = decoder.convert(_data) as List<dynamic>;
|
||||
final int n = result.length;
|
||||
@@ -63,11 +61,7 @@ class Calculator {
|
||||
}
|
||||
|
||||
// The current state of the calculation.
|
||||
enum CalculationState {
|
||||
idle,
|
||||
loading,
|
||||
calculating
|
||||
}
|
||||
enum CalculationState { idle, loading, calculating }
|
||||
|
||||
// Structured message to initialize the spawned isolate.
|
||||
class CalculationMessage {
|
||||
@@ -82,7 +76,7 @@ class CalculationMessage {
|
||||
// This class manages these ports and maintains state related to the
|
||||
// progress of the background computation.
|
||||
class CalculationManager {
|
||||
CalculationManager({ required this.onProgressListener, required this.onResultListener })
|
||||
CalculationManager({required this.onProgressListener, required this.onResultListener})
|
||||
: _receivePort = ReceivePort() {
|
||||
_receivePort.listen(_handleMessage);
|
||||
}
|
||||
@@ -175,7 +169,7 @@ class CalculationManager {
|
||||
final SendPort sender = message.sendPort;
|
||||
final Calculator calculator = Calculator(
|
||||
onProgressListener: (double completed, double total) {
|
||||
sender.send(<double>[ completed, total ]);
|
||||
sender.send(<double>[completed, total]);
|
||||
},
|
||||
onResultListener: sender.send,
|
||||
data: message.data,
|
||||
@@ -201,7 +195,6 @@ class IsolateExampleWidget extends StatefulWidget {
|
||||
|
||||
// Main application state.
|
||||
class IsolateExampleState extends State<StatefulWidget> with SingleTickerProviderStateMixin {
|
||||
|
||||
String _status = 'Idle';
|
||||
String _label = 'Start';
|
||||
String _result = ' ';
|
||||
@@ -229,25 +222,14 @@ class IsolateExampleState extends State<StatefulWidget> with SingleTickerProvide
|
||||
children: <Widget>[
|
||||
RotationTransition(
|
||||
turns: _animation,
|
||||
child: Container(
|
||||
width: 120.0,
|
||||
height: 120.0,
|
||||
color: const Color(0xFF882222),
|
||||
),
|
||||
child: Container(width: 120.0, height: 120.0, color: const Color(0xFF882222)),
|
||||
),
|
||||
Opacity(
|
||||
opacity: _calculationManager.isRunning ? 1.0 : 0.0,
|
||||
child: CircularProgressIndicator(
|
||||
value: _progress,
|
||||
),
|
||||
child: CircularProgressIndicator(value: _progress),
|
||||
),
|
||||
Text(_status),
|
||||
Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: _handleButtonPressed,
|
||||
child: Text(_label),
|
||||
),
|
||||
),
|
||||
Center(child: ElevatedButton(onPressed: _handleButtonPressed, child: Text(_label))),
|
||||
Text(_result),
|
||||
],
|
||||
),
|
||||
@@ -273,9 +255,9 @@ class IsolateExampleState extends State<StatefulWidget> with SingleTickerProvide
|
||||
|
||||
String _getStatus(CalculationState state) {
|
||||
return switch (state) {
|
||||
CalculationState.loading => 'Loading...',
|
||||
CalculationState.loading => 'Loading...',
|
||||
CalculationState.calculating => 'In Progress',
|
||||
CalculationState.idle => 'Idle',
|
||||
CalculationState.idle => 'Idle',
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,13 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class LifecycleWatcher extends StatefulWidget {
|
||||
const LifecycleWatcher({ super.key });
|
||||
const LifecycleWatcher({super.key});
|
||||
|
||||
@override
|
||||
State<LifecycleWatcher> createState() => _LifecycleWatcherState();
|
||||
}
|
||||
|
||||
class _LifecycleWatcherState extends State<LifecycleWatcher>
|
||||
with WidgetsBindingObserver {
|
||||
class _LifecycleWatcherState extends State<LifecycleWatcher> with WidgetsBindingObserver {
|
||||
AppLifecycleState? _lastLifecycleState;
|
||||
|
||||
@override
|
||||
@@ -43,14 +42,11 @@ class _LifecycleWatcherState extends State<LifecycleWatcher>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
runApp(
|
||||
const Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Center(
|
||||
child: LifecycleWatcher(),
|
||||
),
|
||||
child: Center(child: LifecycleWatcher()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user