From 221d6eb20f0316d47176601f45bf341274e60153 Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Wed, 10 Feb 2021 13:21:33 +0530 Subject: [PATCH] feat: Added native and local splash screens --- .../main/res/drawable/launch_background.xml | 9 +- .../app/src/main/res/values/colors.xml | 4 + .../LaunchBackground.imageset/Contents.json | 21 +++ .../LaunchBackground.imageset/background.png | Bin 0 -> 70 bytes .../LaunchImage.imageset/Contents.json | 10 +- .../LaunchImage.imageset/LaunchImage.png | Bin 68 -> 68 bytes .../LaunchImage.imageset/LaunchImage@2x.png | Bin 68 -> 68 bytes .../LaunchImage.imageset/LaunchImage@3x.png | Bin 68 -> 68 bytes .../Runner/Base.lproj/LaunchScreen.storyboard | 17 ++- stream_chat_v1/ios/Runner/Info.plist | 124 +++++++++--------- stream_chat_v1/lib/main.dart | 88 ++++++++----- stream_chat_v1/lib/routes/app_routes.dart | 2 +- 12 files changed, 162 insertions(+), 113 deletions(-) create mode 100644 stream_chat_v1/android/app/src/main/res/values/colors.xml create mode 100644 stream_chat_v1/ios/Runner/Assets.xcassets/LaunchBackground.imageset/Contents.json create mode 100644 stream_chat_v1/ios/Runner/Assets.xcassets/LaunchBackground.imageset/background.png diff --git a/stream_chat_v1/android/app/src/main/res/drawable/launch_background.xml b/stream_chat_v1/android/app/src/main/res/drawable/launch_background.xml index 304732f..3618fa7 100644 --- a/stream_chat_v1/android/app/src/main/res/drawable/launch_background.xml +++ b/stream_chat_v1/android/app/src/main/res/drawable/launch_background.xml @@ -1,12 +1,5 @@ - - - - + diff --git a/stream_chat_v1/android/app/src/main/res/values/colors.xml b/stream_chat_v1/android/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..e0b6c6f --- /dev/null +++ b/stream_chat_v1/android/app/src/main/res/values/colors.xml @@ -0,0 +1,4 @@ + + + #005fff + \ No newline at end of file diff --git a/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchBackground.imageset/Contents.json b/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchBackground.imageset/Contents.json new file mode 100644 index 0000000..9f447e1 --- /dev/null +++ b/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchBackground.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "background.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchBackground.imageset/background.png b/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchBackground.imageset/background.png new file mode 100644 index 0000000000000000000000000000000000000000..36178800c0d2669ed4f42ed918ae2206b9db66d0 GIT binary patch literal 70 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k92}1TpU9x7?Tq_{{NR}U@>M&%4I&Z Q1}MSc>FVdQ&MBb@0IDSp>i_@% literal 0 HcmV?d00001 diff --git a/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json index 0bedcf2..00cabce 100644 --- a/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json +++ b/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json @@ -1,23 +1,23 @@ { "images" : [ { - "idiom" : "universal", "filename" : "LaunchImage.png", + "idiom" : "universal", "scale" : "1x" }, { - "idiom" : "universal", "filename" : "LaunchImage@2x.png", + "idiom" : "universal", "scale" : "2x" }, { - "idiom" : "universal", "filename" : "LaunchImage@3x.png", + "idiom" : "universal", "scale" : "3x" } ], "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } } diff --git a/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png index 9da19eacad3b03bb08bbddbbf4ac48dd78b3d838..67774cf3dacac0ad161013438381c330272b67f7 100644 GIT binary patch delta 48 zcmZ>9nINgn#=yWJFM6aCNO60*IEGX(CMPm5F)&Cnuuk}3_7y11;OXk;vd$@?2>|Y^ B3kv`M delta 48 zcmZ>9nINgn!oa|=RfdNNNO60*IEGZrN&a=7fq{vgk!hBUVIfeM!PC{xWt~$(69DxS B3j+WE diff --git a/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png index 9da19eacad3b03bb08bbddbbf4ac48dd78b3d838..67774cf3dacac0ad161013438381c330272b67f7 100644 GIT binary patch delta 48 zcmZ>9nINgn#=yWJFM6aCNO60*IEGX(CMPm5F)&Cnuuk}3_7y11;OXk;vd$@?2>|Y^ B3kv`M delta 48 zcmZ>9nINgn!oa|=RfdNNNO60*IEGZrN&a=7fq{vgk!hBUVIfeM!PC{xWt~$(69DxS B3j+WE diff --git a/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/stream_chat_v1/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png index 9da19eacad3b03bb08bbddbbf4ac48dd78b3d838..67774cf3dacac0ad161013438381c330272b67f7 100644 GIT binary patch delta 48 zcmZ>9nINgn#=yWJFM6aCNO60*IEGX(CMPm5F)&Cnuuk}3_7y11;OXk;vd$@?2>|Y^ B3kv`M delta 48 zcmZ>9nINgn!oa|=RfdNNNO60*IEGZrN&a=7fq{vgk!hBUVIfeM!PC{xWt~$(69DxS B3j+WE diff --git a/stream_chat_v1/ios/Runner/Base.lproj/LaunchScreen.storyboard b/stream_chat_v1/ios/Runner/Base.lproj/LaunchScreen.storyboard index f2e259c..c9811f0 100644 --- a/stream_chat_v1/ios/Runner/Base.lproj/LaunchScreen.storyboard +++ b/stream_chat_v1/ios/Runner/Base.lproj/LaunchScreen.storyboard @@ -16,13 +16,19 @@ - - + + - - + + + + + + + + @@ -33,5 +39,6 @@ + - + \ No newline at end of file diff --git a/stream_chat_v1/ios/Runner/Info.plist b/stream_chat_v1/ios/Runner/Info.plist index 7e63f46..d9f250b 100644 --- a/stream_chat_v1/ios/Runner/Info.plist +++ b/stream_chat_v1/ios/Runner/Info.plist @@ -1,64 +1,66 @@ - - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ChatSample - CFBundlePackageType - APPL - CFBundleShortVersionString - $(FLUTTER_BUILD_NAME) - CFBundleSignature - ???? - CFBundleVersion - $(FLUTTER_BUILD_NUMBER) - LSRequiresIPhoneOS - - NSAppleMusicUsageDescription - Used to send message attachments - NSCameraUsageDescription - Used to send message attachments - NSMicrophoneUsageDescription - Used to send message attachments - NSPhotoLibraryUsageDescription - Used to send message attachments - UIBackgroundModes - - fetch - remote-notification - - UILaunchStoryboardName - LaunchScreen - UIMainStoryboardFile - Main - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UISupportedInterfaceOrientations~ipad - - UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UIViewControllerBasedStatusBarAppearance - - UIBackgroundModes - - remote-notification - - UIViewControllerBasedStatusBarAppearance - - - + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ChatSample + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleSignature + ???? + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSRequiresIPhoneOS + + NSAppleMusicUsageDescription + Used to send message attachments + NSCameraUsageDescription + Used to send message attachments + NSMicrophoneUsageDescription + Used to send message attachments + NSPhotoLibraryUsageDescription + Used to send message attachments + UIBackgroundModes + + fetch + remote-notification + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + + UIBackgroundModes + + remote-notification + + UIViewControllerBasedStatusBarAppearance + + UIStatusBarHidden + + + \ No newline at end of file diff --git a/stream_chat_v1/lib/main.dart b/stream_chat_v1/lib/main.dart index 3278426..12ec3ac 100644 --- a/stream_chat_v1/lib/main.dart +++ b/stream_chat_v1/lib/main.dart @@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:flutter_svg/flutter_svg.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart'; import 'package:stream_chat_persistence/stream_chat_persistence.dart'; import 'package:streaming_shared_preferences/streaming_shared_preferences.dart'; @@ -24,61 +25,75 @@ final chatPersistentClient = StreamChatPersistenceClient( void main() async { WidgetsFlutterBinding.ensureInitialized(); - final secureStorage = FlutterSecureStorage(); - final apiKey = await secureStorage.read(key: kStreamApiKey); - final userId = await secureStorage.read(key: kStreamUserId); - - final client = StreamChatClient( - apiKey ?? kDefaultStreamApiKey, - logLevel: Level.INFO, - )..chatPersistenceClient = chatPersistentClient; - - if (userId != null) { - final token = await secureStorage.read(key: kStreamToken); - await client.connectUser( - User(id: userId), - token, - ); - } - - runApp(MyApp(client)); + runApp(MyApp()); } class MyApp extends StatelessWidget { - final StreamChatClient client; + Future _initConnection() async { + final secureStorage = FlutterSecureStorage(); - MyApp(this.client); + final apiKey = await secureStorage.read(key: kStreamApiKey); + final userId = await secureStorage.read(key: kStreamUserId); + + final client = StreamChatClient( + apiKey ?? kDefaultStreamApiKey, + logLevel: Level.INFO, + )..chatPersistenceClient = chatPersistentClient; + + if (userId != null) { + final token = await secureStorage.read(key: kStreamToken); + await client.connectUser( + User(id: userId), + token, + ); + } + + var prefs = await StreamingSharedPreferences.instance; + + return InitData(client, prefs); + } @override Widget build(BuildContext context) { - return FutureBuilder( - future: StreamingSharedPreferences.instance, - builder: (context, snapshot) { - if (!snapshot.hasData) { - return SizedBox(); + return FutureBuilder( + future: _initConnection(), + builder: (context, initData) { + if (!initData.hasData) { + return MaterialApp( + home: Container( + alignment: Alignment.center, + color: Colors.white, + child: Container( + height: 80.0, + width: 80.0, + child: SvgPicture.asset('assets/logo.svg'), + ), + ), + ); } + return PreferenceBuilder( - preference: snapshot.data.getInt( + preference: initData.data.preferences.getInt( 'theme', defaultValue: 0, ), builder: (context, snapshot) => MaterialApp( builder: (context, child) { return StreamChat( - client: client, + client: initData.data.client, onBackgroundEventReceived: (e) => - showLocalNotification(e, client.state.user.id), + showLocalNotification(e, initData.data.client.state.user.id), child: Builder( builder: (context) => AnnotatedRegion( child: child, value: SystemUiOverlayStyle( systemNavigationBarColor: - StreamChatTheme.of(context).colorTheme.white, + StreamChatTheme.of(context).colorTheme.white, systemNavigationBarIconBrightness: - Theme.of(context).brightness == Brightness.dark - ? Brightness.light - : Brightness.dark, + Theme.of(context).brightness == Brightness.dark + ? Brightness.light + : Brightness.dark, ), ), ), @@ -94,7 +109,7 @@ class MyApp extends StatelessWidget { }[snapshot], onGenerateRoute: AppRoutes.generateRoute, initialRoute: - client.state.user == null ? Routes.CHOOSE_USER : Routes.HOME, + initData.data.client.state.user == null ? Routes.CHOOSE_USER : Routes.HOME, ), ); }, @@ -833,3 +848,10 @@ class _ThreadPageState extends State { ); } } + +class InitData { + final StreamChatClient client; + final StreamingSharedPreferences preferences; + + InitData(this.client, this.preferences); +} diff --git a/stream_chat_v1/lib/routes/app_routes.dart b/stream_chat_v1/lib/routes/app_routes.dart index e7c7e31..c641b04 100644 --- a/stream_chat_v1/lib/routes/app_routes.dart +++ b/stream_chat_v1/lib/routes/app_routes.dart @@ -19,7 +19,7 @@ class AppRoutes { return MaterialPageRoute( settings: const RouteSettings(name: Routes.APP), builder: (_) { - return MyApp(args); + return MyApp(); }); case Routes.HOME: return MaterialPageRoute(