Flutter Syllabus
Create your flutter projects by using the sample resources, and get your web/apk/ios builds right away
Getting Started
Copy the necessary resource files from the repo
Run the build in an emulator or chrome or press crtl+F5 for debubbing and run or just F5 to run without debugger attached.
IOS Setting Up
Go inside IOS folder
Deintegrate IOS if needed
Update the latest Pod Version
Key Generation
- Debug Key Generation Get to terminal and enter
- Signed Key Generation
Firebase Setting Up
- Setup All firebase Features
- Firebase
AppCheck - Firebase
Authencation(AddGmailasnew providerinsidesign-in-method) - Firebase
Remoteconfig - Firebase
Database - Firebase
Cloudstorage - Firebase
Functions(Only forblazeplan)
- Add keys into the Firebase Projects
- Add a
IOSproject withcom.companyname.appname - Add an
Androidproject withcom.companyname.appname
Bundle Name/ AppName
- The app name or bundle name is used as identifier in
playstoreandappstore - Make sure you also purchase the domain
companyname.comfor better integration - If you have
companyname.indomain, it's also fine, but its better to take.comalso for future proofing - The default name would be
com.example.flutterprojectname
Changing the appname in Android
- Also change
build.gradleinside theappfolder inside android Go toandroid>> app >> build.gradleand change theapplicationIdto your owncom.companyname.appname
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.companyname.appname"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
- Also change in
namespace "com.companyname.appname"
.....
.....
}
- Also add google sign-in in
build.gradleaboveandroid namespace
android {
namespace "com.companyname.appname"
.....
.....
multiDexEnabled true //Make sure you add multi dex
}
Changing the appname in IOS
- Open the ios folder inside your flutter folder
- right click on the folder, and choose
open in xcode - Open the
runner, change the package name tocom.companyname.appname
Quick Change
ctrl+shift+Hfor find and replace- find
com.example.flutterprojectnametocom.companyname.appname
Copy the Firebase service files
Make sure you enable the firebase services and also added your dev SHA1-key into the firebase console
- Then download
google-services.jsonand paste it insideandroid/app/alongsidebuild.gradle - Then download
GoogleService-info.plistand paste it insideios/runneralongsideinfo.plist - Also check the content inside each to verify, your
production-sha-keyanddeveloper-sha-keyare inside the json file - Make sure to write
gitignoreon public projects files, as these files holds the api key acccess for clientside.
**/android/app/google-services.json
# Ignore Google Service Info plist files for iOS in all Flutter projects
**/ios/Runner/GoogleService-Info.plist
Firebase Setting-up in IOS
- Refer
https://pub.dev/packages/google_sign_in - Copy the
REVERSED_CLIENT_IDfromGoogleService-info.plist - If you cant find the
REVERSED_CLIENT_ID, make sure you created and enabledgooglesignin fromauthenticationinsidefirebase console - If you are still facing error, make sure the
bundle IDis same in thexcodeand thefireabase console - Make sure you chane all profiles ,
debug,releaseandprofileto the samebundle id - Change the bundle id through out the app using
find and replaceoption.
- Add the whole code into
info.plistand also change theREVERSED_CLIENT_IDwith copied value
- If get error
impeller not connected, taking longer - Paste this code inside info.plist
FLTEnableImpeller
- If you get error
[FirebaseCore][I-COR000005] No app has been configured yet., make sure you addWidgetsFlutterBinding.ensureInitialized();inmain()
WidgetsFlutterBinding.ensureInitialized(); // Ensure initialisation
await Firebase.initializeApp();
// await Get.put(Database()).initStorage();
runApp(const MyApp()); // This should be called after calling firebase and binding
}
Multidex Error
Change the build.gradle main file.
namespace "com.companyname.appname"
.....
.....
multiDexEnabled true //Make sure you add multi dex
}
PlatformException in Android
-
Make sure you have added google-services.json in
android/app -
Make sure you have added
apply plugin: 'com.google.gms.google-services'in build.gradle (app) -
Make sure you have added
classpath 'com.google.gms:google-services:4.3.15'in build.gradle (main) -
build.gradle (app)
android {
namespace "com.companyname.appname"
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
- build.gradle (main)
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath 'com.google.gms:google-services:4.3.15' // Add this inside dependency for firebase
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Error: FirebaseApp has not been correctly initialized in IOS
- Even tho you have copied the file
GoogleService-info.plistinto the folder, it won't work - You need to manually add to
runnerviaxcode, reffer to the following link
Error: SHAkey or gsm-service error while gmail Sign-In
If you find yourself having gsm.google.service errors, its probably because your debug, production key are not updated on the cloud.google console, even tho you have added in firebase.google.com. If thats the case, you have to do the following steps
- Select the project and go to API and services>
- Credentials > Android key (Edit this auto created by firebase)
- Add the new Key (SHA-1 of the debug) and save
- Wait for 5 seconds
Datamodels
- Goto json to dart converter
- Make the json for the datamodel
"name":"something",
"email":"something@gmail.com",
"date":"15/06/1999",
"time": "3:00 AM",
"timeinmill":5656565
}
- Name the datamodel class as
dm_user - Generate the code
- Copy paste the code to
dm_user.dartunder theDataModelsfolder. - Remember to change the
fromJson,dm_user.fromJson(Maptojson) dynamic,dynamic> - Genereated Version
name = json['name'];
email = json['email'];
date = json['date'];
time = json['time'];
timeinmill = json['timeinmill'];
}
- Right version
name = json['name'];
email = json['email'];
date = json['date'];
time = json['time'];
timeinmill = json['timeinmill'];
}
Lint Yellow Signs
- To disbale yellow warning signs when using print functions
- go to
analysis_options.yamland uncommentavoid_print: falseto not show the warning
# producing the lint.
rules:
avoid_print: false # Uncomment to disable the `avoid_print` rule
Upgrading Compile SDK to 33
- Upgrade the
ext.kotlin_versioninsidebuild.gradleto
- Upgrade the
tools.build:gradleinsidebuild.gradleto
Using imagepicker
- Add the following permission code inside the
info.plistin ios to get access tophoto library
Notification
- add in
pubspec.yaml
flutter_local_notifications: ^16.1.0
# listen for notification
rxdart: ^0.27.7
- add this to
ios>>Runner>>AppDelegate.swift - also add
importfunction on top of theAppDelegate.swift
- add this code inside the
boolfunction, above thereturncallback
GeneratedPluginRegistrant.register(with: registry)}
- just above the
returnstatement
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
- sample code
import Flutter
import flutter_local_notifications //Import for notification
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// For notification
FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in
GeneratedPluginRegistrant.register(with: registry)}
GeneratedPluginRegistrant.register(with: self)
// For notification
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
- add the
initialisationin themain.dart - it shoulde be inside the
mainfunction aboverunApp(const MyApp());
runApp(const MyApp());
- add to android manifest, for API 33 or greater
- add to main function, to request the acess, above
runApp(const MyApp());function
if (value) {
Permission.notification.request();
}
});
runApp(const MyApp());
Error with file_version_info
- change the file at
/Users/name/.pub-cache/hosted/pub.dev/package_info_plus_windows-2.1.0/lib/src/file_version_info.dart - from this
@Uint16()
external int? wLanguage;
@Uint16()
external int? wCodePage;
}
- to this
@Uint16()
external int wLanguage;
@Uint16()
external int wCodePage;
}
Google Maps
- In
Android, Specify your API key in the application manifest android/app/src/main/AndroidManifest.xml
android:value="YOUR KEY HERE"/>
- In
IOS, go toAppDelegate.swiftand alsoimport GoogleMaps
GMSServices.provideAPIKey("YOUR KEY HERE")
Refresh View after adding new data
- There is no method to actually refresh the page
- It can be done on
OninitorBuildstate - So the work arround is to use
asynconontapmethod - and calling
setstateafter the await
onTap: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ActAddChapters(
widget.coursesdata.crKey.toString())),
);
setState(() {});
},
child: AddChaptersButton(),
),
Adding open dial, chrome, whatsap, telegram links
- Add these to manifest.xml on
android - Above the
applicationtag
Creating app logo
- Update the
pubspec.yaml - Change the
icon_backgroundto any color if you want
flutter_test:
sdk: flutter
flutter_launcher_icons: ^0.9.2
flutter_icons:
android: true
ios: true
remove_alpha_ios: true
image_path: "assets/images/stockexlogo.png"
min_sdk_android: 21 # android min sdk min:16, default 21
adaptive_icon_background: "#000000"
adaptive_icon_foreground: "assets/images/logo_foreground.png"
- Create
logo_foreground.pngfrom
- Then finish by running
Get IOS Simulator UUID
- find the uuid and add the simulator as test device in google mobile ads
- Update the
AndroidManifest.xmlundertag
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="@string/admob_app_id" />
- Update
info.plist
Updating to Sequoia
- Find simulator data
open ~/Library/Developer/CoreSimulator
- Deleting unused simulator
xcrun simctl delete unavailable
- Getting some space, deleting cache and other artifacts in android
open ~/.gradle/wrapper/dists/
open ~/.gradle/caches/
Updating the gradle
- Copy the following gradle files
build.gradle.ktsbuild.gradle.ktsin app alsosettings.gradle.ktsgradle-wrapper.propertiesinside the gradle/wrapperproguard-rules.profor minify- Then update the flutter packages to latest
- Update
local.propertieswith
flutter.ndkVersion=27.0.12077973
flutter.compileSdkVersion=36
flutter.targetSdkVersion=36
- Add gitignore
/android/app/.cxx/
- If already added, remove via terminal command
git rm -r --cached android/app/.cxx/