From bef9dd1d2e42ea95e0cc2d03f0a6370013710ef3 Mon Sep 17 00:00:00 2001 From: thinkdigitalsoftware Date: Sun, 10 Nov 2019 17:25:09 -0800 Subject: [PATCH 1/4] Add PlatformBrightness widget to allow automatic updating of the app's theme when the platform changes it's brightness. --- CHANGELOG.md | 4 ++ example/pubspec.lock | 88 ++++++++++++++++++++++++++++++++++-------- lib/dynamic_theme.dart | 13 +++++++ pubspec.lock | 86 ++++++++++++++++++++++++++++++++++------- pubspec.yaml | 7 ++-- 5 files changed, 164 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c2867b..a1e4e74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,3 +5,7 @@ - Update local_storage dependency to latest 0.5.0 - Added and fixed linter rules - Fixed default Dark mode problem from PRs + +## 1.1.0 +- Add PlatformBrightness widget to allow automatic updating of the + app's theme when the platform changes it's brightness. diff --git a/example/pubspec.lock b/example/pubspec.lock index a73b69d..710bd38 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,20 +1,34 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.10" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.3.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" charcode: dependency: transitive description: @@ -29,6 +43,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.14.11" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" cupertino_icons: dependency: "direct main" description: @@ -42,7 +70,7 @@ packages: path: ".." relative: true source: path - version: "1.0.1" + version: "1.1.0" flutter: dependency: "direct main" description: flutter @@ -53,41 +81,62 @@ packages: description: flutter source: sdk version: "0.0.0" + image: + dependency: transitive + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.3+1" + version: "0.12.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.1.7" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.6.4" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.0+1" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.0" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.5" shared_preferences: dependency: transitive description: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "0.5.0" + version: "0.5.4+3" sky_engine: dependency: transitive description: flutter @@ -99,7 +148,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.4.1" + version: "1.5.5" stack_trace: dependency: transitive description: @@ -113,28 +162,28 @@ packages: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "1.6.8" + version: "2.0.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.1" + version: "0.2.5" typed_data: dependency: transitive description: @@ -149,6 +198,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "3.5.0" sdks: - dart: ">=2.0.0 <3.0.0" - flutter: ">=0.1.4 <2.0.0" + dart: ">=2.4.0 <3.0.0" + flutter: ">=1.6.7 <2.0.0" diff --git a/lib/dynamic_theme.dart b/lib/dynamic_theme.dart index d0daa8e..87227d9 100644 --- a/lib/dynamic_theme.dart +++ b/lib/dynamic_theme.dart @@ -9,6 +9,9 @@ typedef ThemedWidgetBuilder = Widget Function( typedef ThemeDataWithBrightnessBuilder = ThemeData Function( Brightness brightness); +typedef SystemBrightnessBuilder = Widget Function( + BuildContext context, Brightness brightness); + class DynamicTheme extends StatefulWidget { const DynamicTheme( {Key key, this.data, this.themedWidgetBuilder, this.defaultBrightness}) @@ -91,3 +94,13 @@ class DynamicThemeState extends State { return widget.themedWidgetBuilder(context, _data); } } + +class PlatformBrightness extends StatelessWidget { + const PlatformBrightness({Key key, @required this.builder}) : super(key: key); + + final SystemBrightnessBuilder builder; + + @override + Widget build(BuildContext context) => + builder(context, MediaQuery.platformBrightnessOf(context)); +} diff --git a/pubspec.lock b/pubspec.lock index 8811910..04f2597 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,20 +1,34 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.10" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.3.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" charcode: dependency: transitive description: @@ -29,6 +43,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.14.11" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" flutter: dependency: "direct main" description: flutter @@ -39,41 +67,62 @@ packages: description: flutter source: sdk version: "0.0.0" + image: + dependency: transitive + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.3+1" + version: "0.12.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.1.7" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" + version: "1.6.4" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.0+1" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.0" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.5" shared_preferences: dependency: "direct main" description: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "0.5.0" + version: "0.5.4+3" sky_engine: dependency: transitive description: flutter @@ -85,7 +134,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.4.1" + version: "1.5.5" stack_trace: dependency: transitive description: @@ -99,28 +148,28 @@ packages: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "1.6.8" + version: "2.0.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.1" + version: "0.2.5" typed_data: dependency: transitive description: @@ -135,6 +184,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "3.5.0" sdks: - dart: ">=2.0.0 <3.0.0" - flutter: ">=0.1.4 <2.0.0" + dart: ">=2.4.0 <3.0.0" + flutter: ">=1.6.7 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 3ac4037..008e667 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,7 @@ name: dynamic_theme -description: Changes the theme during runtime, also presists brightness settings across restarts -version: 1.0.1 +description: A widget that allows you to change your app's theme during runtime. + It also persists brightness settings across restarts +version: 1.1.0 author: 'Norbert Kozsir ' homepage: 'https://github.com/Norbert515/dynamic_theme' @@ -11,7 +12,7 @@ environment: dependencies: flutter: sdk: flutter - shared_preferences: '^0.5.0' + shared_preferences: ^0.5.4+3 dev_dependencies: flutter_test: From 0cedc2233014ca9f74aa7b1a37ce1fb0c0bb5fe0 Mon Sep 17 00:00:00 2001 From: thinkdigitalsoftware Date: Tue, 24 Dec 2019 12:35:45 -0800 Subject: [PATCH 2/4] Add example --- example/.flutter-plugins-dependencies | 1 + example/android/app/build.gradle | 2 +- .../android/app/src/debug/AndroidManifest.xml | 7 +++ .../com/yourcompany/example/MainActivity.kt | 12 +++++ .../app/src/profile/AndroidManifest.xml | 7 +++ example/android/build.gradle | 4 +- example/android/build.gradle.bak | 29 ++++++++++++ example/android/gradle.properties | 1 + .../android/gradle/wrapper/gradle-wrapper.jar | Bin .../gradle/wrapper/gradle-wrapper.properties | 2 +- example/android/gradlew | 0 example/android/gradlew.bat | 0 .../ios/Flutter/flutter_export_environment.sh | 10 +++++ example/ios/Runner/AppDelegate.swift | 13 ++++++ example/ios/Runner/Runner-Bridging-Header.h | 1 + example/lib/main.dart | 42 +++++++++++------- example/pubspec.lock | 40 ++++++++++++++--- pubspec.lock | 40 ++++++++++++++--- pubspec.yaml | 2 +- 19 files changed, 179 insertions(+), 34 deletions(-) create mode 100644 example/.flutter-plugins-dependencies create mode 100644 example/android/app/src/debug/AndroidManifest.xml create mode 100644 example/android/app/src/main/kotlin/com/yourcompany/example/MainActivity.kt create mode 100644 example/android/app/src/profile/AndroidManifest.xml create mode 100644 example/android/build.gradle.bak mode change 100644 => 100755 example/android/gradle/wrapper/gradle-wrapper.jar mode change 100644 => 100755 example/android/gradlew mode change 100644 => 100755 example/android/gradlew.bat create mode 100755 example/ios/Flutter/flutter_export_environment.sh create mode 100644 example/ios/Runner/AppDelegate.swift create mode 100644 example/ios/Runner/Runner-Bridging-Header.h diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies new file mode 100644 index 0000000..ee15714 --- /dev/null +++ b/example/.flutter-plugins-dependencies @@ -0,0 +1 @@ +{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]}]} \ No newline at end of file diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 4fe7712..363754d 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -15,7 +15,7 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 27 + compileSdkVersion 28 lintOptions { disable 'InvalidPackage' diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml new file mode 100644 index 0000000..069b81a --- /dev/null +++ b/example/android/app/src/debug/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/example/android/app/src/main/kotlin/com/yourcompany/example/MainActivity.kt b/example/android/app/src/main/kotlin/com/yourcompany/example/MainActivity.kt new file mode 100644 index 0000000..9de07d2 --- /dev/null +++ b/example/android/app/src/main/kotlin/com/yourcompany/example/MainActivity.kt @@ -0,0 +1,12 @@ +package com.yourcompany.example + +import androidx.annotation.NonNull; +import io.flutter.embedding.android.FlutterActivity +import io.flutter.embedding.engine.FlutterEngine +import io.flutter.plugins.GeneratedPluginRegistrant + +class MainActivity: FlutterActivity() { + override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { + GeneratedPluginRegistrant.registerWith(flutterEngine); + } +} diff --git a/example/android/app/src/profile/AndroidManifest.xml b/example/android/app/src/profile/AndroidManifest.xml new file mode 100644 index 0000000..069b81a --- /dev/null +++ b/example/android/app/src/profile/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/example/android/build.gradle b/example/android/build.gradle index 4476887..232bc0d 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,11 +1,13 @@ buildscript { + ext.kotlin_version = '1.3.50' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' + classpath 'com.android.tools.build:gradle:3.5.3' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/example/android/build.gradle.bak b/example/android/build.gradle.bak new file mode 100644 index 0000000..f9b4826 --- /dev/null +++ b/example/android/build.gradle.bak @@ -0,0 +1,29 @@ +buildscript { + repositories { + google() + jcenter() + } + + dependencies { + classpath 'com.android.tools.build:gradle:4.10.1' + } +} + +allprojects { + repositories { + google() + jcenter() + } +} + +rootProject.buildDir = '../build' +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" +} +subprojects { + project.evaluationDependsOn(':app') +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 8bd86f6..7be3d8b 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1 +1,2 @@ org.gradle.jvmargs=-Xmx1536M +android.enableR8=true diff --git a/example/android/gradle/wrapper/gradle-wrapper.jar b/example/android/gradle/wrapper/gradle-wrapper.jar old mode 100644 new mode 100755 diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index aa901e1..296b146 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip diff --git a/example/android/gradlew b/example/android/gradlew old mode 100644 new mode 100755 diff --git a/example/android/gradlew.bat b/example/android/gradlew.bat old mode 100644 new mode 100755 diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh new file mode 100755 index 0000000..bb97dc8 --- /dev/null +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=/Users/thinkdigital/development/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/thinkdigital/IdeaProjects/dynamic_theme/example" +export "FLUTTER_TARGET=lib/main.dart" +export "FLUTTER_BUILD_DIR=build" +export "SYMROOT=${SOURCE_ROOT}/../build/ios" +export "FLUTTER_FRAMEWORK_DIR=/Users/thinkdigital/development/flutter/bin/cache/artifacts/engine/ios" +export "FLUTTER_BUILD_NAME=1.0.1" +export "FLUTTER_BUILD_NUMBER=1.0.1" diff --git a/example/ios/Runner/AppDelegate.swift b/example/ios/Runner/AppDelegate.swift new file mode 100644 index 0000000..70693e4 --- /dev/null +++ b/example/ios/Runner/AppDelegate.swift @@ -0,0 +1,13 @@ +import UIKit +import Flutter + +@UIApplicationMain +@objc class AppDelegate: FlutterAppDelegate { + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + GeneratedPluginRegistrant.register(with: self) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } +} diff --git a/example/ios/Runner/Runner-Bridging-Header.h b/example/ios/Runner/Runner-Bridging-Header.h new file mode 100644 index 0000000..308a2a5 --- /dev/null +++ b/example/ios/Runner/Runner-Bridging-Header.h @@ -0,0 +1 @@ +#import "GeneratedPluginRegistrant.h" diff --git a/example/lib/main.dart b/example/lib/main.dart index 18a601f..9082356 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -2,7 +2,6 @@ import 'package:dynamic_theme/dynamic_theme.dart'; import 'package:dynamic_theme/theme_switcher_widgets.dart'; import 'package:flutter/material.dart'; - void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @@ -10,11 +9,11 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return DynamicTheme( defaultBrightness: Brightness.light, - data: (brightness) => ThemeData( + data: (Brightness brightness) => ThemeData( primarySwatch: Colors.indigo, brightness: brightness, ), - themedWidgetBuilder: (context, theme) { + themedWidgetBuilder: (BuildContext context, ThemeData theme) { return MaterialApp( title: 'Flutter Demo', theme: theme, @@ -39,20 +38,31 @@ class _MyHomePageState extends State { appBar: AppBar( title: Text("Easy Theme"), ), - body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - RaisedButton( - onPressed: changeBrightness, - child: const Text("Change brightness"), - ), - RaisedButton( - onPressed: changeColor, - child: const Text("Change color"), + body: PlatformBrightness( + builder: (BuildContext context, Brightness platformBrightness) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'Platform brightness: ${platformBrightness == Brightness.light ? 'light' : 'dark'}', + style: TextStyle(fontSize: 30), + ), + Padding( + padding: EdgeInsets.symmetric(vertical: 10), + ), + RaisedButton( + onPressed: changeBrightness, + child: const Text("Change brightness"), + ), + RaisedButton( + onPressed: changeColor, + child: const Text("Change color"), + ), + ], ), - ], - ), + ); + }, ), floatingActionButton: FloatingActionButton( onPressed: showChooser, diff --git a/example/pubspec.lock b/example/pubspec.lock index 710bd38..a892f0e 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: name: archive url: "https://pub.dartlang.org" source: hosted - version: "2.0.10" + version: "2.0.11" args: dependency: transitive description: @@ -21,7 +21,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.4.0" boolean_selector: dependency: transitive description: @@ -81,6 +81,11 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" image: dependency: transitive description: @@ -94,14 +99,14 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.6" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" + version: "1.1.8" path: dependency: transitive description: @@ -136,7 +141,28 @@ packages: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "0.5.4+3" + version: "0.5.6" + shared_preferences_macos: + dependency: transitive + description: + name: shared_preferences_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+3" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2+2" sky_engine: dependency: transitive description: flutter @@ -183,7 +209,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.11" typed_data: dependency: transitive description: @@ -207,4 +233,4 @@ packages: version: "3.5.0" sdks: dart: ">=2.4.0 <3.0.0" - flutter: ">=1.6.7 <2.0.0" + flutter: ">=1.12.13+hotfix.4 <2.0.0" diff --git a/pubspec.lock b/pubspec.lock index 04f2597..2f6662a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: archive url: "https://pub.dartlang.org" source: hosted - version: "2.0.10" + version: "2.0.11" args: dependency: transitive description: @@ -21,7 +21,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.4.0" boolean_selector: dependency: transitive description: @@ -67,6 +67,11 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" image: dependency: transitive description: @@ -80,14 +85,14 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.6" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.7" + version: "1.1.8" path: dependency: transitive description: @@ -122,7 +127,28 @@ packages: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "0.5.4+3" + version: "0.5.6" + shared_preferences_macos: + dependency: transitive + description: + name: shared_preferences_macos + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+3" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.2+2" sky_engine: dependency: transitive description: flutter @@ -169,7 +195,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.11" typed_data: dependency: transitive description: @@ -193,4 +219,4 @@ packages: version: "3.5.0" sdks: dart: ">=2.4.0 <3.0.0" - flutter: ">=1.6.7 <2.0.0" + flutter: ">=1.12.13+hotfix.4 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 008e667..56e1a83 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ environment: dependencies: flutter: sdk: flutter - shared_preferences: ^0.5.4+3 + shared_preferences: ^0.5.6 dev_dependencies: flutter_test: From 5505397bff098a3f66c7553d145361a42e13d5e5 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Tue, 24 Dec 2019 12:36:56 -0800 Subject: [PATCH 3/4] Delete .flutter-plugins-dependencies --- example/.flutter-plugins-dependencies | 1 - 1 file changed, 1 deletion(-) delete mode 100644 example/.flutter-plugins-dependencies diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies deleted file mode 100644 index ee15714..0000000 --- a/example/.flutter-plugins-dependencies +++ /dev/null @@ -1 +0,0 @@ -{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]}]} \ No newline at end of file From 5de0f1a84a877f7d47eda98326b3fa213ba6dd75 Mon Sep 17 00:00:00 2001 From: thinkdigitalsoftware Date: Fri, 27 Dec 2019 13:55:48 -0800 Subject: [PATCH 4/4] Add an error if no MediaQuery widget is found --- example/ios/.symlinks/flutter | 1 + .../ios/.symlinks/plugins/shared_preferences | 1 + .../plugins/shared_preferences_macos | 1 + .../.symlinks/plugins/shared_preferences_web | 1 + .../ios/Flutter/flutter_export_environment.sh | 3 +- example/ios/Podfile.lock | 34 +++++++++ example/ios/Runner.xcodeproj/project.pbxproj | 72 +++++++++++++++++-- .../contents.xcworkspacedata | 3 + example/lib/main.dart | 13 ++-- lib/dynamic_theme.dart | 11 ++- 10 files changed, 127 insertions(+), 13 deletions(-) create mode 120000 example/ios/.symlinks/flutter create mode 120000 example/ios/.symlinks/plugins/shared_preferences create mode 120000 example/ios/.symlinks/plugins/shared_preferences_macos create mode 120000 example/ios/.symlinks/plugins/shared_preferences_web create mode 100644 example/ios/Podfile.lock diff --git a/example/ios/.symlinks/flutter b/example/ios/.symlinks/flutter new file mode 120000 index 0000000..e8d00f2 --- /dev/null +++ b/example/ios/.symlinks/flutter @@ -0,0 +1 @@ +/Users/thinkdigital/development/flutter/bin/cache/artifacts/engine \ No newline at end of file diff --git a/example/ios/.symlinks/plugins/shared_preferences b/example/ios/.symlinks/plugins/shared_preferences new file mode 120000 index 0000000..cb19436 --- /dev/null +++ b/example/ios/.symlinks/plugins/shared_preferences @@ -0,0 +1 @@ +/Users/thinkdigital/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.6 \ No newline at end of file diff --git a/example/ios/.symlinks/plugins/shared_preferences_macos b/example/ios/.symlinks/plugins/shared_preferences_macos new file mode 120000 index 0000000..aa07ffb --- /dev/null +++ b/example/ios/.symlinks/plugins/shared_preferences_macos @@ -0,0 +1 @@ +/Users/thinkdigital/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+3 \ No newline at end of file diff --git a/example/ios/.symlinks/plugins/shared_preferences_web b/example/ios/.symlinks/plugins/shared_preferences_web new file mode 120000 index 0000000..6a717eb --- /dev/null +++ b/example/ios/.symlinks/plugins/shared_preferences_web @@ -0,0 +1 @@ +/Users/thinkdigital/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+2 \ No newline at end of file diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index bb97dc8..016e6a9 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -2,9 +2,10 @@ # This is a generated file; do not edit or check into version control. export "FLUTTER_ROOT=/Users/thinkdigital/development/flutter" export "FLUTTER_APPLICATION_PATH=/Users/thinkdigital/IdeaProjects/dynamic_theme/example" -export "FLUTTER_TARGET=lib/main.dart" +export "FLUTTER_TARGET=/Users/thinkdigital/IdeaProjects/dynamic_theme/example/lib/main.dart" export "FLUTTER_BUILD_DIR=build" export "SYMROOT=${SOURCE_ROOT}/../build/ios" export "FLUTTER_FRAMEWORK_DIR=/Users/thinkdigital/development/flutter/bin/cache/artifacts/engine/ios" export "FLUTTER_BUILD_NAME=1.0.1" export "FLUTTER_BUILD_NUMBER=1.0.1" +export "TRACK_WIDGET_CREATION=true" diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock new file mode 100644 index 0000000..b718afe --- /dev/null +++ b/example/ios/Podfile.lock @@ -0,0 +1,34 @@ +PODS: + - Flutter (1.0.0) + - shared_preferences (0.0.1): + - Flutter + - shared_preferences_macos (0.0.1): + - Flutter + - shared_preferences_web (0.0.1): + - Flutter + +DEPENDENCIES: + - Flutter (from `.symlinks/flutter/ios`) + - shared_preferences (from `.symlinks/plugins/shared_preferences/ios`) + - shared_preferences_macos (from `.symlinks/plugins/shared_preferences_macos/ios`) + - shared_preferences_web (from `.symlinks/plugins/shared_preferences_web/ios`) + +EXTERNAL SOURCES: + Flutter: + :path: ".symlinks/flutter/ios" + shared_preferences: + :path: ".symlinks/plugins/shared_preferences/ios" + shared_preferences_macos: + :path: ".symlinks/plugins/shared_preferences_macos/ios" + shared_preferences_web: + :path: ".symlinks/plugins/shared_preferences_web/ios" + +SPEC CHECKSUMS: + Flutter: 0e3d915762c693b495b44d77113d4970485de6ec + shared_preferences: 430726339841afefe5142b9c1f50cb6bd7793e01 + shared_preferences_macos: f3f29b71ccbb56bf40c9dd6396c9acf15e214087 + shared_preferences_web: 141cce0c3ed1a1c5bf2a0e44f52d31eeb66e5ea9 + +PODFILE CHECKSUM: aff02bfeed411c636180d6812254b2daeea14d09 + +COCOAPODS: 1.8.4 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 7fd3612..664e365 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -8,10 +8,10 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 8D7ED93D0D95A6150329BC5D /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 017390FFF1DC104C44578E03 /* libPods-Runner.a */; }; 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; @@ -39,11 +39,12 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 017390FFF1DC104C44578E03 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; + 4436E859CBD5C7BD5765CEC2 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -56,6 +57,7 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + B2D7ECB7FEC2E48E2E5C4742 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -65,16 +67,34 @@ files = ( 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, + 8D7ED93D0D95A6150329BC5D /* libPods-Runner.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 36BB7C6B5BFCB8A6A544F291 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 017390FFF1DC104C44578E03 /* libPods-Runner.a */, + ); + name = Frameworks; + sourceTree = ""; + }; + 4883C6B99955C599D6DF4352 /* Pods */ = { + isa = PBXGroup; + children = ( + 4436E859CBD5C7BD5765CEC2 /* Pods-Runner.debug.xcconfig */, + B2D7ECB7FEC2E48E2E5C4742 /* Pods-Runner.release.xcconfig */, + ); + name = Pods; + path = Pods; + sourceTree = ""; + }; 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 2D5378251FAA1A9400D5DBA9 /* flutter_assets */, 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 9740EEBA1CF902C7004384FC /* Flutter.framework */, @@ -91,7 +111,8 @@ 9740EEB11CF90186004384FC /* Flutter */, 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, - CF3B75C9A7D2FA2A4C99F110 /* Frameworks */, + 4883C6B99955C599D6DF4352 /* Pods */, + 36BB7C6B5BFCB8A6A544F291 /* Frameworks */, ); sourceTree = ""; }; @@ -134,12 +155,14 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( + A7DD6A135E635C644D6CBDB2 /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + CEAC110BE5F32F191AA52C02 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -192,7 +215,6 @@ 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, - 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */, 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -228,6 +250,46 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; }; + A7DD6A135E635C644D6CBDB2 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + CEAC110BE5F32F191AA52C02 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", + "${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcworkspace/contents.xcworkspacedata index 1d526a1..21a3cc1 100644 --- a/example/ios/Runner.xcworkspace/contents.xcworkspacedata +++ b/example/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -4,4 +4,7 @@ + + diff --git a/example/lib/main.dart b/example/lib/main.dart index 9082356..139226e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -14,11 +14,14 @@ class MyApp extends StatelessWidget { brightness: brightness, ), themedWidgetBuilder: (BuildContext context, ThemeData theme) { - return MaterialApp( - title: 'Flutter Demo', - theme: theme, - home: MyHomePage(title: 'Flutter Demo Home Page'), - ); + return PlatformBrightness( + builder: (BuildContext context, Brightness platformBrightness) { + return MaterialApp( + title: 'Flutter Demo', + theme: theme, + home: MyHomePage(title: 'Flutter Demo Home Page'), + ); + }); }); } } diff --git a/lib/dynamic_theme.dart b/lib/dynamic_theme.dart index 87227d9..f83b97a 100644 --- a/lib/dynamic_theme.dart +++ b/lib/dynamic_theme.dart @@ -101,6 +101,13 @@ class PlatformBrightness extends StatelessWidget { final SystemBrightnessBuilder builder; @override - Widget build(BuildContext context) => - builder(context, MediaQuery.platformBrightnessOf(context)); + Widget build(BuildContext context) { + final MediaQueryData mediaQuery = MediaQuery.of(context, nullOk: true); + if (mediaQuery == null) { + throw FlutterError('No MediaQuery widget found within this context. \n' + 'PlatformBrightness widgets must be placed below the WidgetsApp widget (MaterialApp, CupertinoApp or WidgetsApp) \n' + 'in order to return an accurate platform brightness.'); + } + return builder(context, MediaQuery.platformBrightnessOf(context)); + } }