Skip to content

Commit

Permalink
[sync] 2023/12/02 (#1390)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Dec 4, 2023
2 parents c563c1b + 38f7cc3 commit 7789745
Show file tree
Hide file tree
Showing 84 changed files with 1,467 additions and 4,638 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ruby:3.2.2-slim-bookworm@sha256:adc7f93df5b83c8627b3fadcc974ce452ef9999603f65f637e32b8acec096ae1 AS base
FROM ruby:3.2.2-slim-bookworm@sha256:02a091c83d1aa1070c0f6fefcbd2aff58ddd3430e2d5661c6ef2142b1383349b AS base

SHELL ["/usr/bin/bash", "-c"]

Expand Down
2 changes: 1 addition & 1 deletion examples/codelabs
Submodule codelabs updated 292 files
18 changes: 13 additions & 5 deletions examples/cookbook/networking/authenticated_requests/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ class Album {
});

factory Album.fromJson(Map<String, dynamic> json) {
return Album(
userId: json['userId'] as int,
id: json['id'] as int,
title: json['title'] as String,
);
return switch (json) {
{
'userId': int userId,
'id': int id,
'title': String title,
} =>
Album(
userId: userId,
id: id,
title: title,
),
_ => throw const FormatException('Failed to load album.'),
};
}
}
15 changes: 11 additions & 4 deletions examples/cookbook/networking/delete_data/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@ class Album {
const Album({required this.id, required this.title});

factory Album.fromJson(Map<String, dynamic> json) {
return Album(
id: json['id'] as int,
title: json['title'] as String,
);
return switch (json) {
{
'id': int id,
'title': String title,
} =>
Album(
id: id,
title: title,
),
_ => throw const FormatException('Failed to load album.'),
};
}
}

Expand Down
18 changes: 13 additions & 5 deletions examples/cookbook/networking/fetch_data/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ class Album {
});

factory Album.fromJson(Map<String, dynamic> json) {
return Album(
userId: json['userId'] as int,
id: json['id'] as int,
title: json['title'] as String,
);
return switch (json) {
{
'userId': int userId,
'id': int id,
'title': String title,
} =>
Album(
userId: userId,
id: id,
title: title,
),
_ => throw const FormatException('Failed to load album.'),
};
}
}
// #enddocregion Album
Expand Down
15 changes: 11 additions & 4 deletions examples/cookbook/networking/send_data/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,17 @@ class Album {
const Album({required this.id, required this.title});

factory Album.fromJson(Map<String, dynamic> json) {
return Album(
id: json['id'] as int,
title: json['title'] as String,
);
return switch (json) {
{
'id': int id,
'title': String title,
} =>
Album(
id: id,
title: title,
),
_ => throw const FormatException('Failed to load album.'),
};
}
}
// #enddocregion Album
Expand Down
15 changes: 11 additions & 4 deletions examples/cookbook/networking/update_data/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ class Album {
const Album({required this.id, required this.title});

factory Album.fromJson(Map<String, dynamic> json) {
return Album(
id: json['id'] as int,
title: json['title'] as String,
);
return switch (json) {
{
'id': int id,
'title': String title,
} =>
Album(
id: id,
title: title,
),
_ => throw const FormatException('Failed to load album.'),
};
}
}
// #enddocregion Album
Expand Down
15 changes: 11 additions & 4 deletions examples/cookbook/networking/update_data/lib/main_step5.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ class Album {
const Album({required this.id, required this.title});

factory Album.fromJson(Map<String, dynamic> json) {
return Album(
id: json['id'] as int,
title: json['title'] as String,
);
return switch (json) {
{
'id': int id,
'title': String title,
} =>
Album(
id: id,
title: title,
),
_ => throw const FormatException('Failed to load album.'),
};
}
}

Expand Down
10 changes: 10 additions & 0 deletions examples/development/concurrency/isolates/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Take our settings from the example_utils analysis_options.yaml file.
# If necessary for a particular example, this file can also include
# overrides for individual lints.

include: package:example_utils/analysis.yaml

linter:
rules:
avoid_print: false
prefer_const_constructors: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'dart:isolate';

import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
// Identify the root isolate to pass to the background isolate.
RootIsolateToken rootIsolateToken = RootIsolateToken.instance!;
Isolate.spawn(_isolateMain, rootIsolateToken);
}

Future<void> _isolateMain(RootIsolateToken rootIsolateToken) async {
// Register the background isolate with the root isolate.
BackgroundIsolateBinaryMessenger.ensureInitialized(rootIsolateToken);

// You can now use the shared_preferences plugin.
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();

print(sharedPreferences.getBool('isDebug'));
}
71 changes: 71 additions & 0 deletions examples/development/concurrency/isolates/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2021 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:convert';
import 'dart:isolate';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Isolates demo',
home: Scaffold(
appBar: AppBar(
title: const Text('Isolates demo'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
getPhotos();
},
child: Text('Fetch photos'),
),
),
),
);
}
}

// #docregion isolate-run
// Produces a list of 211,640 photo objects.
// (The JSON file is ~20MB.)
Future<List<Photo>> getPhotos() async {
final String jsonString = await rootBundle.loadString('assets/photos.json');
final List<Photo> photos = await Isolate.run<List<Photo>>(() {
final List<Object?> photoData = jsonDecode(jsonString) as List<Object?>;
return photoData.cast<Map<String, Object?>>().map(Photo.fromJson).toList();
});
return photos;
}
// #enddocregion isolate-run

class Photo {
final int albumId;
final int id;
final String title;
final String thumbnailUrl;

Photo({
required this.albumId,
required this.id,
required this.title,
required this.thumbnailUrl,
});

factory Photo.fromJson(Map<String, dynamic> data) {
return Photo(
albumId: data['albumId'] as int,
id: data['id'] as int,
title: data['title'] as String,
thumbnailUrl: data['thumbnailUrl'] as String,
);
}
}
17 changes: 17 additions & 0 deletions examples/development/concurrency/isolates/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: isolates
description: Sample isolate code

version: 1.0.0+1

environment:
sdk: ^3.1.0

dependencies:
flutter:
sdk: flutter
shared_preferences: any

dev_dependencies:
example_utils:
path: ../../../example_utils

2 changes: 1 addition & 1 deletion examples/development/platform_integration/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ environment:
dependencies:
flutter:
sdk: flutter
pigeon: ^13.0.0
pigeon: ^14.0.0

cupertino_icons: ^1.0.6

Expand Down
1 change: 1 addition & 0 deletions examples/example_utils/lib/analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ linter:
- package_api_docs
- prefer_relative_imports
- prefer_single_quotes
- only_throw_errors
- sort_unnamed_constructors_first
- test_types_in_equals
- throw_in_finally
Expand Down
6 changes: 0 additions & 6 deletions examples/get-started/codelab_web/lib/starter.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* {$ begin main.dart $} */
import 'package:flutter/material.dart';

void main() => runApp(const SignUpApp());
Expand Down Expand Up @@ -99,8 +98,3 @@ class _SignUpFormState extends State<SignUpForm> {
);
}
}
/* {$ end main.dart $} */
/* {$ begin test.dart $} */
// Avoid warning on "double _formProgress = 0;"
//_ignore_for_file: prefer_final_fields
/* {$ end test.dart $} */
2 changes: 1 addition & 1 deletion examples/googleapis/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
flutter:
sdk: flutter
google_sign_in: ^6.1.5
googleapis: ^11.4.0
googleapis: ^12.0.0
http: ^1.1.0

dev_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/errors/lib/excerpts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MyApp extends StatelessWidget {
}
ErrorWidget.builder = (errorDetails) => error;
if (widget != null) return widget;
throw ('widget is null');
throw StateError('widget is null');
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/errors/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MyApp extends StatelessWidget {
}
ErrorWidget.builder = (errorDetails) => error;
if (widget != null) return widget;
throw ('widget is null');
throw StateError('widget is null');
},
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sdk.dir=/Users/brettmorgan/Library/Android/sdk
flutter.sdk=/Users/brettmorgan/flutter
41 changes: 41 additions & 0 deletions examples/testing/integration_tests/how_to/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Generated file. Do not edit.
//

// clang-format off

#ifndef GeneratedPluginRegistrant_h
#define GeneratedPluginRegistrant_h

#import <Flutter/Flutter.h>

NS_ASSUME_NONNULL_BEGIN

@interface GeneratedPluginRegistrant : NSObject
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry;
@end

NS_ASSUME_NONNULL_END
#endif /* GeneratedPluginRegistrant_h */
Loading

0 comments on commit 7789745

Please sign in to comment.