Amad 6
Amad 6
Solutions (Detailed)
Contents
1 Unit 6 2
1.1 How do you configure the build.gradle file for release mode in a Flutter app? 2
1.2 What is the process to set the application label (app name) in Android
and iOS? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 How can you add a custom launcher icon in a Flutter project using the
flutter_launcher_icons package? . . . . . . . . . . . . . . . . . . . . . . 4
1.4 What are the required changes in AndroidManifest.xml to reflect the new
app icon or app name? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5 Describe the steps to implement a splash screen for both Android and iOS
in Flutter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.6 How do you customize the splash screen background color and image for
an Android Flutter app? . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.7 What is the difference between debug and release build modes in Flutter? 8
1.8 What command is used to generate a signed APK for Android deployment? 9
1.9 How can you generate and use a keystore for signing an Android Flutter
app? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.10 Which tools are required to publish a Flutter app on the Google Play Store? 10
1.11 What are the prerequisites for deploying a Flutter app to the Apple App
Store? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.12 How do you set up provisioning profiles and signing certificates for iOS
deployment? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.13 Explain the role of Xcode in building and publishing iOS Flutter applications. 12
1.14 What command is used to compile and generate web assets in a Flutter
web app? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.15 How do you host a Flutter web app using GitHub Pages or Firebase Hosting? 13
1.16 What files are generated in the build/web folder after building a Flutter
web app? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.17 What are the benefits and limitations of deploying a Flutter app to the web? 14
2 Programming Questions 15
2.1 Create a simple UI design to demonstrate the use of ElevatedButton and
Container Widgets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.2 Create a simple UI design to demonstrate the use of Text and Image Widgets. 16
2.3 Write a Flutter code to implement state management. (Change the states) 17
2.4 Create an app with five screens and switch between them using buttons . 18
2.5 Create a simple code to demonstrate asynchronous data loading using Fu-
tureBuilder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.6 Write a short note on how an e-commerce app fetches product data from
an API. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1 Unit 6
1.1 How do you configure the build.gradle file for release mode in a Flutter
app?
To configure the build.gradle file for release mode in a Flutter Android app, you need
to set up signing configurations and build types. This ensures the app is optimized,
signed, and ready for distribution.
1. Project-Level build.gradle (android/build.gradle):
• Ensure repositories and dependencies are set for Android builds.
• Example:
1 buildscript {
2 repositories {
3 google ()
4 mavenCentral ()
5 }
6 dependencies {
7 classpath ’ com . android . tools . build : gradle :8.1.0 ’
8 }
9 }
10 allprojects {
11 repositories {
12 google ()
13 mavenCentral ()
14 }
15 }
17 }
18 buildTypes {
19 release {
20 signingConfig signingConfigs . release
21 minifyEnabled true
22 shrinkResources true
23 proguardFiles g e t D e f a u l t P r o g u a r d F i l e ( ’
proguard - android - optimize . txt ’) , ’ proguard
- rules . pro ’
24 }
25 }
26 }
27 dependencies {
28 implementation ’ androidx . core : core :1.12.0 ’
29 }
3. Key Points:
• signingConfigs: Defines the keystore for signing the APK/AAB.
• minifyEnabled: Enables code shrinking with R8.
• shrinkResources: Removes unused resources.
• proguardFiles: Applies obfuscation rules to reduce app size and protect code.
Use Case: This configuration ensures a Flutter e-commerce app is optimized (e.g., 20%
smaller) and securely signed for Google Play deployment.
1.2 What is the process to set the application label (app name) in Android
and iOS?
The application label (app name) is set differently for Android and iOS in a Flutter
project:
• Android:
1. Open android/app/src/main/AndroidManifest.xml.
2. Set the android:label attribute in the application tag:
1 < application
2 android:label = " My Flutter App "
3 android:icon = " @mipmap / ic_launcher " >
4. For flavors (e.g., dev, prod), define separate strings.xml files in flavor-specific
folders (e.g., android/app/src/dev/res/values/).
• iOS:
1. Open ios/Runner/Info.plist in Xcode or a text editor.
2. Update the CFBundleName key:
1 < key > CFBundleName </ key >
2 < string > My Flutter App </ string >
3. Alternatively, edit in Xcodes project settings under Target > General >
Display Name.
• Flutter-Level Consistency:
– Update pubspec.yaml to reflect the app name for consistency:
1 name : my_flutter_app
2 description : A new Flutter project .
1.3 How can you add a custom launcher icon in a Flutter project using the
flutter_launcher_icons package?
The flutter_launcher_icons package automates generating launcher icons for Android
and iOS.
1. Add Dependency:
• In pubspec.yaml:
1 dev_dependencies :
2 flu tt er _ la u n c h e r _ i c o n s : ^0.13.1
Update android/app/src/main/res/values/strings.xml:
1 < string name = " app_name " > New App Name </ string >
2. App Icon:
• Ensure android:icon points to the correct mipmap resource:
1 < application
2 android:label = " New App Name "
3 android:icon = " @mipmap / ic_launcher " >
1.5 Describe the steps to implement a splash screen for both Android and
iOS in Flutter.
A splash screen displays a logo or branding during app launch. Flutter supports native
splash screens for Android and iOS using the flutter_native_splash package.
1. Add Dependency:
1 dev_dependencies :
2 flut t er_n at iv e _ s p l a s h : ^2.4.0
1.6 How do you customize the splash screen background color and image for
an Android Flutter app?
To customize the splash screen for Android:
1. Use flutter_native_splash:
• Configure in pubspec.yaml:
1 fl ut t er_n at i v e _ s p l a s h :
2 color : "#42 A5F5 "
3 image : assets / splash . png
4 android : true
Example: A gaming app sets a vibrant red splash background (#FF0000) with a centered
logo, ensuring high-resolution display on Android devices.
1.7 What is the difference between debug and release build modes in Flut-
ter?
Flutter supports multiple build modes, with debug and release being the most common:
• Debug Mode:
– Purpose: Development and testing.
– Characteristics:
∗ Includes debugging symbols and tools (e.g., hot reload).
∗ Larger app size due to unoptimized code.
∗ Slower performance (uses JIT compilation).
∗ Assert statements are enabled.
– Command: flutter run or flutter run –debug.
– Use Case: Testing UI changes in a to-do app with hot reload.
• Release Mode:
– Purpose: Production deployment.
– Characteristics:
∗ Optimized with AOT compilation for speed.
∗ Minified code and resources (smaller size, e.g., 20% reduction).
∗ No debugging symbols; assert statements are disabled.
∗ Faster performance (e.g., smoother animations).
– Command: flutter run –release or flutter build apk –release.
– Use Case: Deploying a shopping app to Google Play with optimal perfor-
mance.
• Key Differences:
1.8 What command is used to generate a signed APK for Android deploy-
ment?
To generate a signed APK for Android:
1. Ensure Signing Configuration: Set up signingConfigs in android/app/build.gradle
(see Question 1).
2. Build Command:
1 flutter build apk -- release
1.9 How can you generate and use a keystore for signing an Android Flutter
app?
A keystore is required to sign Android APKs/AABs for authenticity.
1. Generate Keystore:
• Run:
1 keytool - genkey -v - keystore mykeystore . jks - keyalg RSA -
keysize 2048 - validity 10000 - alias mykey
4 keyPassword ’ password ’
5 storeFile file ( ’ mykeystore . jks ’)
6 storePassword ’ password ’
7 }
8 }
9 buildTypes {
10 release {
11 signingConfig signingConfigs . release
12 }
13 }
• Load in build.gradle:
1 def k ey sto re P r o p e r t i e s F i l e = rootProject . file (" key .
properties ")
2 def keystor eP ro pe rt ies = new Properties ()
3 keystorePro pe rt ie s . load ( new FileInputStream (
key s t or eP r o p e r t i e s F i l e ) )
4
5 signingConfigs {
6 release {
7 keyAlias ke ys to re Pro pe rt ie s [ ’ keyAlias ’]
8 keyPassword ke ys to re Pr op ert ie s [ ’ keyPassword ’]
9 storeFile file ( key st or eP ro pe rt ie s [ ’ storeFile ’])
10 storePassword ke ys tor eP ro pe rt ie s [ ’ storePassword ’]
11 }
12 }
Example: A delivery app generates a keystore, configures it, and builds a signed AAB
for secure Play Store deployment.
1.10 Which tools are required to publish a Flutter app on the Google Play
Store?
• Flutter SDK: For building the app (flutter build appbundle).
• Android Studio: Configures Android SDK, Gradle, and emulators for testing.
• Keytool: Generates keystores for signing (part of JDK).
• Google Play Console: Manages app listings, uploads AABs, and tracks metrics
($25 one-time fee).
• Bundletool: Tests AABs locally (bundletool build-apks).
• Git: Manages version control for collaborative development.
• Image Editing Tools: Creates Play Store assets (e.g., Photoshop for icons, screen-
shots).
Example: A developer uses Android Studio to build a Flutter app, keytool for signing,
and Google Play Console to publish a fitness tracker app.
1.11 What are the prerequisites for deploying a Flutter app to the Apple
App Store?
• Apple Developer Account: $99/year for App Store access.
• MacOS Device: Required for Xcode and iOS builds.
• Xcode: Version 15+ for building, signing, and uploading apps.
• Flutter SDK: Configured for iOS builds (flutter doctor).
• Provisioning Profiles and Certificates: For code signing (see Question 12).
• App Store Connect: Manages app metadata, screenshots, and submissions.
• iOS Device/Simulator: For testing on various screen sizes (e.g., iPhone 14, iPad).
• App-Specific Details:
– Unique bundle ID (e.g., com.example.myapp).
– App icon set (via flutter_launcher_icons).
– Privacy policy and compliance with App Store guidelines.
Example: A meditation app requires an Apple Developer account, Xcode, and a provi-
sioning profile to submit to the App Store.
1.12 How do you set up provisioning profiles and signing certificates for iOS
deployment?
1. Apple Developer Account:
• Enroll at https://developer.apple.com ($99/year).
2. Create App ID:
• In the Apple Developer Portal, go to Identifiers > App IDs.
• Register a unique bundle ID (e.g., com.example.myapp).
3. Generate Certificates:
• In the Portal, go to Certificates > Create Certificate.
• Create an iOS Distribution certificate.
1.13 Explain the role of Xcode in building and publishing iOS Flutter ap-
plications.
Xcode is Apples IDE, critical for iOS Flutter apps:
• Building: Compiles Flutters Dart code and native iOS components (Swift/Objective-
C) into an IPA file using flutter build ios.
• Device Testing: Manages iOS simulators and physical devices for debugging.
• Signing: Configures provisioning profiles and certificates for code signing (manu-
ally or automatically).
• Asset Management: Handles icons, launch screens, and other resources in Assets.xcassets.
• Publishing: Uses Archive to create an IPA and uploads it to App Store Connect
via Application Loader or Transporter.
• Configuration: Edits Info.plist and project settings (e.g., entitlements, capa-
bilities like push notifications).
Example: For a Flutter chat app, Xcode configures push notifications, signs the build,
and uploads the IPA to App Store Connect.
1.14 What command is used to compile and generate web assets in a Flutter
web app?
To compile a Flutter app for web:
1.15 How do you host a Flutter web app using GitHub Pages or Firebase
Hosting?
• GitHub Pages:
1. Build the web app: flutter build web.
2. Create a GitHub repository (e.g., myapp).
3. Push the build/web contents to a gh-pages branch:
1 git add build / web
2 git commit -m " Deploy web app "
3 git subtree push -- prefix build / web origin gh - pages
4. In the repository settings, enable GitHub Pages for the gh-pages branch.
5. Access the app at https://username.github.io/myapp.
• Firebase Hosting:
1. Install Firebase CLI: npm install -g firebase-tools.
2. Login: firebase login.
3. Initialize hosting: firebase init hosting in the Flutter project root.
4. Set public directory to build/web in firebase.json.
5. Build the app: flutter build web.
6. Deploy: firebase deploy.
7. Access at the provided Firebase URL (e.g., https://myapp.web.app).
Example: A blog app uses Firebase Hosting for fast, scalable deployment with automatic
SSL, while GitHub Pages suits a simple portfolio.
1.16 What files are generated in the build/web folder after building a Flutter
web app?
Running flutter build web generates:
• index.html: Entry point for the web app, loading Flutter scripts.
• main.dart.js: Compiled Dart code as JavaScript.
• flutter_service_worker.js: Service worker for offline support (PWA).
• assets/: Fonts, images, and other resources from pubspec.yaml.
• canvaskit/ (if CanvasKit renderer): WebAssembly for advanced graphics.
• manifest.json: PWA configuration for icons and metadata.
• version.json: Build metadata.
Example: A dashboard apps build/web includes index.html for rendering and assets/images/logo.pn
for branding.
1.17 What are the benefits and limitations of deploying a Flutter app to the
web?
• Benefits:
– Single Codebase: Reuse mobile app code for web, reducing development
time (e.g., 90% code reuse in a news app).
– Broad Reach: Accessible on browsers without installation (e.g., Chrome,
Safari).
– PWA Support: Offline capabilities and installable apps (e.g., a task app as
a PWA).
– Fast Deployment: Hosting on Firebase or GitHub Pages is quick and scal-
able.
• Limitations:
– Performance: Web apps are slower than native due to JavaScript (e.g., 30%
slower animations).
– Limited Native Access: No direct hardware access (e.g., camera, GPS).
– Size: CanvasKit renderer increases size (e.g., 10 MB vs. 2 MB with HTML
renderer).
– Browser Compatibility: Some features may vary across browsers (e.g., Sa-
fari quirks).
Example: A Flutter e-commerce web app offers broad access but may need optimization
for smooth scrolling compared to its native version.
2 Programming Questions
2.1 Create a simple UI design to demonstrate the use of ElevatedButton
and Container Widgets.
This code creates a screen with a styled Container and an ElevatedButton that prints
a message when clicked.
1 import ’ package : flutter / material . dart ’;
2
42 );
43 }
44 }
Explanation: - Container: Styles a card-like box with padding, a light blue back-
ground, rounded corners, and a shadow. - ElevatedButton: Triggers a console print
when pressed, styled with a blue background and white text. - Use Case: A login screen
with a styled button in a card.
2.2 Create a simple UI design to demonstrate the use of Text and Image
Widgets.
This code displays a centered Text and Image widget.
1 import ’ package : flutter / material . dart ’;
2
Explanation: - Text: Displays a bold, green title with a large font. - Image.asset:
Loads a local image (add assets/nature.jpg to pubspec.yaml). - Setup: Add to
pubspec.yaml:
1 flutter :
2 assets :
3 - assets / nature . jpg
- Use Case: A travel apps homepage with a title and hero image.
22 void _incrementCounter () {
23 setState (() {
24 _counter ++;
25 }) ;
26 }
27
28 @override
29 Widget build ( BuildContext context ) {
30 return Scaffold (
31 appBar : AppBar ( title : Text ( ’ Counter App ’) ) ,
32 body : Center (
33 child : Column (
34 mainAxisAlig nment : MainAx isAli gnment . center ,
35 children : [
36 Text ( ’ Count : $_counter ’ , style : TextStyle ( fontSize :
24) ) ,
2.4 Create an app with five screens and switch between them using buttons
This code creates an app with five screens, navigable via buttons.
1 import ’ package : flutter / material . dart ’;
2
32 );
33 }
34 }
35
81 }
82 }
83
2.6 Write a short note on how an e-commerce app fetches product data from
an API.
An e-commerce app fetches product data from a REST API to display items like clothing
or electronics. The process involves:
• API Request: The app uses the http package to send a GET request to an
endpoint (e.g., https://api.shop.com/products).
• JSON Parsing: The API returns JSON data (e.g., {"id": 1, "name": "Shirt",
"price": 29.99}), which is parsed into Dart models using jsonDecode and a
Product class with fromJson.
• State Management: The fetched data is stored in a state management solution
(e.g., Provider) to update the UI.
• UI Display: A FutureBuilder or ListView.builder renders the products in a
grid or list, showing names, prices, and images.
• Error Handling: The app handles errors (e.g., network failures) with try-catch
and displays a retry button.
Example: Amazons Flutter app fetches product JSON, maps it to Product objects, and
displays items in a GridView, with caching via dio for offline access.