Skip to content

Commit

Permalink
Minor code refactoring,
Browse files Browse the repository at this point in the history
Added banner ad
  • Loading branch information
Bhavik Makwana committed Feb 6, 2022
1 parent b436733 commit 66ceaf3
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ build/
/android/misc/api-8857670977859340350-9644-c1e382e20443.json
.flutter-plugins-dependencies
.dart_tool/
/android/app/flutter_playground.jks
/upload_certificate.pem
/lib/ads/ad_helper.dart
/android/app/release/
/ios/Flutter/flutter_export_environment.sh
3 changes: 2 additions & 1 deletion android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
/captures
GeneratedPluginRegistrant.java
/misc/flutterplayground.jks
/key.properties
/key.properties
/app/src/main/res/values/strings.xml
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.ibhavikmakwana.flutterplayground"
minSdkVersion 20
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
22 changes: 19 additions & 3 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
-->
<uses-permission android:name="android.permission.INTERNET"/>

<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
</queries>

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
Expand Down Expand Up @@ -41,8 +56,9 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!--<meta-data-->
<!--android:name="com.google.android.gms.ads.APPLICATION_ID"-->
<!--android:value="[ADMOB_APP_ID]" />-->

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="@string/ad_app_pub"/>
</application>
</manifest>
4 changes: 4 additions & 0 deletions android/app/src/main/res/values/test_strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--<string name="ad_app_pub">ca-app-pub-3940256099942544~3347511713</string>-->
</resources>
1 change: 1 addition & 0 deletions assets/images/ic_github.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions lib/ads/test_ad_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'dart:io';

class AdHelper {
static String get bannerAdUnitId {
if (Platform.isAndroid) {
return "ca-app-pub-3940256099942544/6300978111";
} else {
throw new UnsupportedError("Unsupported platform");
}
}
}
5 changes: 2 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter_playground/store/theme_store.dart';
import 'package:provider/provider.dart';

import 'package:flutter_playground/my_app.dart';
import 'package:flutter_playground/store/theme_store.dart';
import 'package:flutter_playground/values/imports.dart';
import 'package:provider/provider.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/staggeredanimation/StaggerDemo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class StaggerAnimation extends StatelessWidget {
final Animation<double> width;
final Animation<double> height;
final Animation<EdgeInsets> padding;
final Animation<BorderRadius> borderRadius;
final Animation<BorderRadius?> borderRadius;
final Animation<Color?> color;

// This function is called each time the controller "ticks" a frame.
Expand Down
70 changes: 62 additions & 8 deletions lib/ui_ux/home_page/my_home_page.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:flutter_playground/ads/ad_helper.dart';
import 'package:flutter_playground/store/theme_store.dart';
import 'package:flutter_playground/ui_ux/home_page/my_home_page_store.dart';
import 'package:flutter_playground/ui_ux/open_source_licenses.dart';
import 'package:flutter_playground/ui_ux/search_widget.dart';
import 'package:flutter_playground/values/assets.dart';
import 'package:flutter_playground/values/imports.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';

import 'package:flutter_playground/ui_ux/home_page/my_home_page_store.dart';

class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
Expand All @@ -19,12 +23,37 @@ class MyHomePage extends StatefulWidget {

class _MyHomePageState extends State<MyHomePage> {
MyHomePageStore? store;
late BannerAd _ad;
bool _isAdLoaded = false;

@override
void initState() {
super.initState();
_initGoogleMobileAds();
_ad = BannerAd(
adUnitId: AdHelper.bannerAdUnitId,
size: AdSize.banner,
request: const AdRequest(),
listener: BannerAdListener(
onAdLoaded: (_) {
setState(() {
_isAdLoaded = true;
});
},
onAdFailedToLoad: (ad, error) {
// Releases an ad resource when it fails to load
ad.dispose();

log('Ad load failed (code=${error.code} message=${error.message})');
},
),
);
_ad.load();
}

Future<InitializationStatus> _initGoogleMobileAds() =>
MobileAds.instance.initialize();

@override
void didChangeDependencies() {
store ??= Provider.of<MyHomePageStore>(context);
Expand All @@ -33,6 +62,7 @@ class _MyHomePageState extends State<MyHomePage> {

@override
void dispose() {
_ad.dispose();
super.dispose();
}

Expand Down Expand Up @@ -72,9 +102,23 @@ class _MyHomePageState extends State<MyHomePage> {
SafeArea(
child: Container(
margin: const EdgeInsets.all(16),
child: Text(
widget.title,
style: Theme.of(context).textTheme.headline6,
child: Row(
children: [
Expanded(
child: Text(
widget.title,
style: Theme.of(context).textTheme.headline6,
),
),
IconButton(
onPressed: () {
_launchURL(
'https://github.com/ibhavikmakwana/FlutterPlayground',
);
},
icon: SvgPicture.asset(Assets.icGithub),
),
],
),
),
),
Expand All @@ -92,6 +136,15 @@ class _MyHomePageState extends State<MyHomePage> {
),
),
),
if (_isAdLoaded)
Center(
child: Container(
width: _ad.size.width.toDouble(),
height: 72.0,
alignment: Alignment.center,
child: AdWidget(ad: _ad),
),
),
Flexible(
child: _buildExampleItemsWidget(),
),
Expand Down Expand Up @@ -141,7 +194,9 @@ class _MyHomePageState extends State<MyHomePage> {
const Divider(),
ListTile(
title: const Text('Privacy Policy'),
onTap: _launchURL,
onTap: () => _launchURL(
'https://flutter-playground.flycricket.io/privacy.html',
),
),
],
),
Expand All @@ -163,8 +218,7 @@ class _MyHomePageState extends State<MyHomePage> {
);
}

Future<void> _launchURL() async {
const url = 'https://flutter-playground.flycricket.io/privacy.html';
Future<void> _launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
Expand Down
1 change: 1 addition & 0 deletions lib/values/assets.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Assets {
static const String featureGraphic = 'assets/images/feature-graphic.png';
static const String appIcon = 'assets/images/ic_launcher.png';
static const String icGithub = 'assets/images/ic_github.svg';
}
4 changes: 3 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: A Flutter application contains a list of Flutter Examples.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.2.7+10
version: 1.2.9+170

environment:
sdk: ">=2.12.0 <3.0.0"
Expand All @@ -35,13 +35,15 @@ dependencies:
webview_flutter: ^2.0.4
firebase_analytics: ^8.0.4
firebase_core: ^1.1.1
flutter_svg:

dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.0.3
mobx_codegen: ^2.0.1+3
lint: ^1.5.3
google_mobile_ads: ^0.13.4

# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
Expand Down

0 comments on commit 66ceaf3

Please sign in to comment.