Skip to content
This repository has been archived by the owner on Jun 5, 2021. It is now read-only.

Null safety #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 16 additions & 47 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
platform :ios, '9.0'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all these iOS specific changes part of the null safety work?

I don't have an iOS device to test this on, so just curious if this is the best practice in latest Flutter dev or something.


# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand All @@ -10,60 +10,29 @@ project 'Runner', {
'Release' => :release,
}

def parse_KV_file(file, separator='=')
file_abs_path = File.expand_path(file)
if !File.exists? file_abs_path
return [];
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
pods_ary = []
skip_line_start_symbols = ["#", "/"]
File.foreach(file_abs_path) { |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
pods_ary.push({:name => podname, :path => podpath});
else
puts "Invalid plugin specification: #{line}"
end
}
return pods_ary

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

target 'Runner' do
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

# Flutter Pods
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
if generated_xcode_build_settings.empty?
puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
end
generated_xcode_build_settings.map { |p|
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
symlink = File.join('.symlinks', 'flutter')
File.symlink(File.dirname(p[:path]), symlink)
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
end
}
flutter_ios_podfile_setup

# Plugin Pods
plugin_pods = parse_KV_file('../.flutter-plugins')
plugin_pods.map { |p|
symlink = File.join('.symlinks', 'plugins', p[:name])
File.symlink(p[:path], symlink)
pod p[:name], :path => File.join(symlink, 'ios')
}
target 'Runner' do
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
flutter_additional_ios_build_settings(target)
end
end
6 changes: 3 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class MyApp extends StatefulWidget {
}

class _MyAppState extends State<MyApp> {
String _userAgent = '<unknown>';
String _webUserAgent = '<unknown>';
String? _userAgent = '<unknown>';
String? _webUserAgent = '<unknown>';

@override
void initState() {
Expand All @@ -23,7 +23,7 @@ class _MyAppState extends State<MyApp> {

// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initUserAgentState() async {
String userAgent, webViewUserAgent;
String? userAgent, webViewUserAgent;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
userAgent = await FlutterUserAgent.getPropertyAsync('userAgent');
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ publish_to: 'none'
version: 1.0.0+1

environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
Expand Down
18 changes: 9 additions & 9 deletions lib/flutter_user_agent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter/services.dart';
class FlutterUserAgent {
static const MethodChannel _channel = MethodChannel('flutter_user_agent');

static Map<String, dynamic> _properties;
static Map<String, dynamic>? _properties;

/// Initialize the module.
///
Expand All @@ -16,7 +16,7 @@ class FlutterUserAgent {
static Future init({force: false}) async {
if (_properties == null || force) {
_properties =
Map.unmodifiable(await _channel.invokeMethod('getProperties'));
Map.unmodifiable(await (_channel.invokeMethod('getProperties')));
}
}

Expand All @@ -27,28 +27,28 @@ class FlutterUserAgent {
}

/// Returns the device's user agent.
static String get userAgent {
return _properties['userAgent'];
static String? get userAgent {
return _properties!['userAgent'];
}

/// Returns the device's webview user agent.
static String get webViewUserAgent {
return _properties['webViewUserAgent'];
static String? get webViewUserAgent {
return _properties!['webViewUserAgent'];
}

/// Fetch a [property] that can be used to build your own user agent string.
static dynamic getProperty(String property) {
return _properties[property];
return _properties![property];
}

/// Fetch a [property] asynchronously that can be used to build your own user agent string.
static dynamic getPropertyAsync(String property) async {
await init();
return _properties[property];
return _properties![property];
}

/// Return a map of properties that can be used to generate the user agent string.
static Map<String, dynamic> get properties {
static Map<String, dynamic>? get properties {
return _properties;
}
}
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: flutter_user_agent
description: Retrieve device and webview user agent strings for Android and iOS devices.

It also provides you with simple building blocks for generating your own user agent string.
version: 1.2.2
version: 2.0.0
homepage: https://github.com/j0j00/flutter_user_agent

environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
Expand Down