-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
84 changed files
with
1,467 additions
and
4,638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
examples/development/concurrency/isolates/analysis_options.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
20 changes: 20 additions & 0 deletions
20
examples/development/concurrency/isolates/lib/isolate_binary_messenger.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
examples/testing/integration_tests/how_to/android/local.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
19 changes: 19 additions & 0 deletions
19
examples/testing/integration_tests/how_to/ios/Runner/GeneratedPluginRegistrant.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
Oops, something went wrong.