mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 14:58:34 +00:00
Flutter 3.29 beta (#2571)
This commit is contained in:
@@ -16,21 +16,17 @@ main() async {
|
||||
print(json.encode({'firstFrame': analyzer.onFirstFrame.value}));
|
||||
});
|
||||
analyzer.onFirstPaint.addListener(() {
|
||||
print(json.encode({
|
||||
'firstPaint': analyzer.onFirstPaint.value?.$1,
|
||||
'firstContentfulPaint': analyzer.onFirstPaint.value?.$2,
|
||||
}));
|
||||
print(
|
||||
json.encode({
|
||||
'firstPaint': analyzer.onFirstPaint.value?.$1,
|
||||
'firstContentfulPaint': analyzer.onFirstPaint.value?.$2,
|
||||
}),
|
||||
);
|
||||
});
|
||||
analyzer.onAdditionalFrames.addListener(() {
|
||||
print(json.encode({
|
||||
'additionalFrames': analyzer.onAdditionalFrames.value,
|
||||
}));
|
||||
print(json.encode({'additionalFrames': analyzer.onAdditionalFrames.value}));
|
||||
});
|
||||
runApp(
|
||||
WebStartupAnalyzerSample(
|
||||
analyzer: analyzer,
|
||||
),
|
||||
);
|
||||
runApp(WebStartupAnalyzerSample(analyzer: analyzer));
|
||||
}
|
||||
|
||||
class WebStartupAnalyzerSample extends StatelessWidget {
|
||||
@@ -102,12 +98,14 @@ class _WebStartupAnalyzerScreenState extends State<WebStartupAnalyzerScreen> {
|
||||
),
|
||||
if (widget.analyzer.firstPaint != null)
|
||||
TimingWidget(
|
||||
name: 'First paint',
|
||||
timingMs: widget.analyzer.firstPaint!),
|
||||
name: 'First paint',
|
||||
timingMs: widget.analyzer.firstPaint!,
|
||||
),
|
||||
if (widget.analyzer.firstContentfulPaint != null)
|
||||
TimingWidget(
|
||||
name: 'First contentful paint',
|
||||
timingMs: widget.analyzer.firstContentfulPaint!),
|
||||
name: 'First contentful paint',
|
||||
timingMs: widget.analyzer.firstContentfulPaint!,
|
||||
),
|
||||
if (widget.analyzer.additionalFrames != null) ...[
|
||||
for (var i in widget.analyzer.additionalFrames!)
|
||||
TimingWidget(name: 'Frame', timingMs: i.toDouble()),
|
||||
@@ -130,11 +128,7 @@ class TimingWidget extends StatelessWidget {
|
||||
final String name;
|
||||
final double timingMs;
|
||||
|
||||
const TimingWidget({
|
||||
super.key,
|
||||
required this.name,
|
||||
required this.timingMs,
|
||||
});
|
||||
const TimingWidget({super.key, required this.name, required this.timingMs});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -3,7 +3,7 @@ description: "flutter_web_startup_analyzer example"
|
||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
version: 1.0.0+1
|
||||
environment:
|
||||
sdk: ^3.5.0
|
||||
sdk: ^3.7.0-0
|
||||
flutter: ^3.16.0
|
||||
dependencies:
|
||||
flutter:
|
||||
|
||||
@@ -16,7 +16,7 @@ class FrameAnalyzer {
|
||||
List<int> additionalFrameTimes = [];
|
||||
|
||||
FrameAnalyzer(this._binding, {this.additionalFrames = 10})
|
||||
: _remainingFrames = additionalFrames;
|
||||
: _remainingFrames = additionalFrames;
|
||||
|
||||
Future<void> captureAdditionalFrames() {
|
||||
_binding.addTimingsCallback(_timingsCallback);
|
||||
|
||||
@@ -52,9 +52,11 @@ class WebStartupAnalyzer extends WebStartupAnalyzerBase {
|
||||
List<int>? get additionalFrames => _additionalFrames;
|
||||
|
||||
WebStartupAnalyzer({int additionalFrameCount = 5})
|
||||
: _widgetsBinding = WidgetsFlutterBinding.ensureInitialized() {
|
||||
_frameAnalyzer =
|
||||
FrameAnalyzer(_widgetsBinding, additionalFrames: additionalFrameCount);
|
||||
: _widgetsBinding = WidgetsFlutterBinding.ensureInitialized() {
|
||||
_frameAnalyzer = FrameAnalyzer(
|
||||
_widgetsBinding,
|
||||
additionalFrames: additionalFrameCount,
|
||||
);
|
||||
_captureStartupMetrics();
|
||||
startupTiming = {
|
||||
'domContentLoaded': domContentLoaded,
|
||||
@@ -76,8 +78,11 @@ class WebStartupAnalyzer extends WebStartupAnalyzerBase {
|
||||
_additionalFrames = value;
|
||||
onAdditionalFrames.value = value;
|
||||
});
|
||||
onChange =
|
||||
Listenable.merge([onFirstFrame, onFirstPaint, onAdditionalFrames]);
|
||||
onChange = Listenable.merge([
|
||||
onFirstFrame,
|
||||
onFirstPaint,
|
||||
onAdditionalFrames,
|
||||
]);
|
||||
}
|
||||
|
||||
_captureStartupMetrics() {
|
||||
|
||||
@@ -3,7 +3,7 @@ description: "Captures web startup timing data in a Flutter web app"
|
||||
version: 0.1.0-wip
|
||||
|
||||
environment:
|
||||
sdk: ^3.5.0
|
||||
sdk: ^3.7.0-0
|
||||
flutter: ^3.16.0
|
||||
|
||||
dependencies:
|
||||
|
||||
@@ -11,14 +11,14 @@ const ignoredDirectories = [
|
||||
'_tool',
|
||||
'_packages/web_startup_analyzer',
|
||||
'_packages/web_startup_analyzer/example',
|
||||
'samples_index'
|
||||
'samples_index',
|
||||
];
|
||||
|
||||
void main() async {
|
||||
final packageDirs = [
|
||||
...listPackageDirs(Directory.current)
|
||||
.map((path) => p.relative(path, from: Directory.current.path))
|
||||
.where((path) => !ignoredDirectories.contains(path))
|
||||
.where((path) => !ignoredDirectories.contains(path)),
|
||||
];
|
||||
|
||||
print('Building the sample index...');
|
||||
@@ -26,8 +26,9 @@ void main() async {
|
||||
await _run('samples_index', 'flutter', ['pub', 'run', 'grinder', 'deploy']);
|
||||
|
||||
// Create the directory each Flutter Web sample lives in
|
||||
Directory(p.join(Directory.current.path, 'samples_index', 'public', 'web'))
|
||||
.createSync(recursive: true);
|
||||
Directory(
|
||||
p.join(Directory.current.path, 'samples_index', 'public', 'web'),
|
||||
).createSync(recursive: true);
|
||||
|
||||
for (var i = 0; i < packageDirs.length; i++) {
|
||||
var directory = packageDirs[i];
|
||||
@@ -36,10 +37,19 @@ void main() async {
|
||||
|
||||
// Create the target directory
|
||||
var directoryName = p.basename(directory);
|
||||
var sourceBuildDir =
|
||||
p.join(Directory.current.path, directory, 'build', 'web');
|
||||
var targetDirectory = p.join(Directory.current.path, 'samples_index',
|
||||
'public', 'web', directoryName);
|
||||
var sourceBuildDir = p.join(
|
||||
Directory.current.path,
|
||||
directory,
|
||||
'build',
|
||||
'web',
|
||||
);
|
||||
var targetDirectory = p.join(
|
||||
Directory.current.path,
|
||||
'samples_index',
|
||||
'public',
|
||||
'web',
|
||||
directoryName,
|
||||
);
|
||||
|
||||
// Build the sample and copy the files
|
||||
await _run(directory, 'flutter', ['pub', 'get']);
|
||||
@@ -53,7 +63,10 @@ void main() async {
|
||||
|
||||
// Invokes run() and exits if the sub-process failed.
|
||||
Future<void> _run(
|
||||
String workingDir, String commandName, List<String> args) async {
|
||||
String workingDir,
|
||||
String commandName,
|
||||
List<String> args,
|
||||
) async {
|
||||
var success = await run(workingDir, commandName, args);
|
||||
if (!success) {
|
||||
exit(1);
|
||||
|
||||
@@ -9,7 +9,10 @@ const ansiRed = 31;
|
||||
const ansiMagenta = 35;
|
||||
|
||||
Future<bool> run(
|
||||
String workingDir, String commandName, List<String> args) async {
|
||||
String workingDir,
|
||||
String commandName,
|
||||
List<String> args,
|
||||
) async {
|
||||
var commandDescription = '`${([commandName, ...args]).join(' ')}`';
|
||||
|
||||
logWrapped(ansiMagenta, ' Running $commandDescription');
|
||||
@@ -25,7 +28,9 @@ Future<bool> run(
|
||||
|
||||
if (exitCode != 0) {
|
||||
logWrapped(
|
||||
ansiRed, ' Failed! ($exitCode) – $workingDir – $commandDescription');
|
||||
ansiRed,
|
||||
' Failed! ($exitCode) – $workingDir – $commandDescription',
|
||||
);
|
||||
return false;
|
||||
} else {
|
||||
logWrapped(ansiGreen, ' Success! – $workingDir – $commandDescription');
|
||||
|
||||
@@ -13,12 +13,14 @@ Future<void> main() async {
|
||||
/// contain `<base href="/samples/web/navigation_and_routing/">`
|
||||
Future<void> fixBaseTags() async {
|
||||
print('currentDir = ${Directory.current.path}');
|
||||
var builtSamplesDir = Directory(p.joinAll([
|
||||
// Parent directory
|
||||
...p.split(Directory.current.path),
|
||||
// path to built samples
|
||||
...p.split('samples_index/public/web')
|
||||
]));
|
||||
var builtSamplesDir = Directory(
|
||||
p.joinAll([
|
||||
// Parent directory
|
||||
...p.split(Directory.current.path),
|
||||
// path to built samples
|
||||
...p.split('samples_index/public/web'),
|
||||
]),
|
||||
);
|
||||
if (!await builtSamplesDir.exists()) {
|
||||
print('${builtSamplesDir.path} does not exist.');
|
||||
exit(1);
|
||||
@@ -40,7 +42,9 @@ Future<void> fixBaseTags() async {
|
||||
continue;
|
||||
}
|
||||
var newContents = contents.replaceFirst(
|
||||
regex, '<base href="/samples/web/$sampleDirName/">');
|
||||
regex,
|
||||
'<base href="/samples/web/$sampleDirName/">',
|
||||
);
|
||||
await index.writeAsString(newContents);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,8 +66,10 @@ void _updateHtml(File htmlFile, String buildDir, String exampleDir) {
|
||||
|
||||
final newContent = content
|
||||
.replaceFirst('<head>', '<head>\n$_analytics')
|
||||
.replaceFirst(_emptyTitle,
|
||||
'<title>${_prettyName(exampleDir)} - Flutter web sample</title>');
|
||||
.replaceFirst(
|
||||
_emptyTitle,
|
||||
'<title>${_prettyName(exampleDir)} - Flutter web sample</title>',
|
||||
);
|
||||
|
||||
if (newContent == content) {
|
||||
print('!!! Did not replace contents in $filePath');
|
||||
@@ -79,10 +81,13 @@ void _updateHtml(File htmlFile, String buildDir, String exampleDir) {
|
||||
|
||||
final _underscoreOrSlash = RegExp('_|/');
|
||||
|
||||
String _prettyName(String input) =>
|
||||
input.split(_underscoreOrSlash).where((e) => e.isNotEmpty).map((e) {
|
||||
String _prettyName(String input) => input
|
||||
.split(_underscoreOrSlash)
|
||||
.where((e) => e.isNotEmpty)
|
||||
.map((e) {
|
||||
return e.substring(0, 1).toUpperCase() + e.substring(1);
|
||||
}).join(' ');
|
||||
})
|
||||
.join(' ');
|
||||
|
||||
// flutter.github.io
|
||||
const _analyticsId = 'UA-67589403-8';
|
||||
|
||||
@@ -2,7 +2,7 @@ name: tool
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
sdk: ^3.5.0
|
||||
sdk: ^3.7.0-0
|
||||
|
||||
dependencies:
|
||||
markdown: ^7.0.0
|
||||
|
||||
@@ -9,10 +9,11 @@ import 'package:path/path.dart' as p;
|
||||
import 'common.dart';
|
||||
|
||||
void main() async {
|
||||
final packageDirs = listPackageDirs(Directory.current)
|
||||
.map((path) => p.relative(path, from: Directory.current.path))
|
||||
.where((path) => !p.dirname(path).startsWith('_'))
|
||||
.toList();
|
||||
final packageDirs =
|
||||
listPackageDirs(Directory.current)
|
||||
.map((path) => p.relative(path, from: Directory.current.path))
|
||||
.where((path) => !p.dirname(path).startsWith('_'))
|
||||
.toList();
|
||||
|
||||
print('Package dirs:\n${packageDirs.map((path) => ' $path').join('\n')}');
|
||||
|
||||
@@ -34,11 +35,14 @@ void main() async {
|
||||
results.add(false);
|
||||
continue;
|
||||
}
|
||||
results.add(await run(
|
||||
dir,
|
||||
'dart',
|
||||
['analyze', '--fatal-infos', '--fatal-warnings', '.'],
|
||||
));
|
||||
results.add(
|
||||
await run(dir, 'dart', [
|
||||
'analyze',
|
||||
'--fatal-infos',
|
||||
'--fatal-warnings',
|
||||
'.',
|
||||
]),
|
||||
);
|
||||
_printStatus(results);
|
||||
}
|
||||
|
||||
@@ -52,6 +56,8 @@ void _printStatus(List<bool> results) {
|
||||
var success = (successCount == results.length);
|
||||
var pct = 100 * successCount / results.length;
|
||||
|
||||
logWrapped(success ? ansiGreen : ansiRed,
|
||||
'$successCount of ${results.length} (${pct.toStringAsFixed(2)}%)');
|
||||
logWrapped(
|
||||
success ? ansiGreen : ansiRed,
|
||||
'$successCount of ${results.length} (${pct.toStringAsFixed(2)}%)',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ dependencies:
|
||||
mdc_web: ^0.6.0
|
||||
path: ^1.8.3
|
||||
sass_builder: ^2.2.1
|
||||
web: ^1.1.0
|
||||
yaml: ^3.1.2
|
||||
|
||||
dev_dependencies:
|
||||
|
||||
Reference in New Issue
Block a user