Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
16 changes: 13 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 30
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -36,8 +46,8 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.flutter.udemy_flutter"
minSdkVersion 16
targetSdkVersion 30
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
multiDexEnabled true
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
5 changes: 4 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
package="com.flutter.udemy_flutter">
<application
android:label="udemy_flutter"
android:icon="@mipmap/ic_launcher">
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"

android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
Expand Down
8 changes: 4 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.7.0'
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.5'
}
Expand All @@ -15,7 +15,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
2 changes: 1 addition & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
);
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";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # debugPrint 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;
};
/* End PBXShellScriptBuildPhase section */
Expand Down
56 changes: 29 additions & 27 deletions lib/layout/news_app/cubit/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ class NewsCubit extends Cubit<NewsStates>

List<BottomNavigationBarItem> bottomItems =
[
BottomNavigationBarItem(
const BottomNavigationBarItem(
icon: Icon(
Icons.business,
),
label: 'Business',
),
BottomNavigationBarItem(
const BottomNavigationBarItem(
icon: Icon(
Icons.sports,
),
label: 'Sports',
),
BottomNavigationBarItem(
const BottomNavigationBarItem(
icon: Icon(
Icons.science,
),
Expand All @@ -38,22 +38,24 @@ class NewsCubit extends Cubit<NewsStates>

List<Widget> screens =
[
BusinessScreen(),
SportsScreen(),
ScienceScreen(),
const BusinessScreen(),
const SportsScreen(),
const ScienceScreen(),
];

void changeBottomNavBar(int index)
{
currentIndex = index;
if(index == 1)
if(index == 1) {
getSports();
if(index == 2)
}
if(index == 2) {
getScience();
}
emit(NewsBottomNavState());
}

List<dynamic> business = [];
List<dynamic>? business = [];

void getBusiness()
{
Expand All @@ -69,24 +71,24 @@ class NewsCubit extends Cubit<NewsStates>
},
).then((value)
{
//print(value.data['articles'][0]['title']);
//debugPrint(value.data['articles'][0]['title']);
business = value.data['articles'];
print(business[0]['title']);
debugPrint(business![0]['title']);

emit(NewsGetBusinessSuccessState());
}).catchError((error){
print(error.toString());
debugPrint(error.toString());
emit(NewsGetBusinessErrorState(error.toString()));
});
}

List<dynamic> sports = [];
List<dynamic>? sports = [];

void getSports()
{
emit(NewsGetSportsLoadingState());

if(sports.length == 0)
if(sports!.isEmpty)
{
DioHelper.getData(
url: 'v2/top-headlines',
Expand All @@ -98,13 +100,13 @@ class NewsCubit extends Cubit<NewsStates>
},
).then((value)
{
//print(value.data['articles'][0]['title']);
//debugPrint(value.data['articles'][0]['title']);
sports = value.data['articles'];
print(sports[0]['title']);
debugPrint(sports![0]['title']);

emit(NewsGetSportsSuccessState());
}).catchError((error){
print(error.toString());
debugPrint(error.toString());
emit(NewsGetSportsErrorState(error.toString()));
});
} else
Expand All @@ -113,13 +115,13 @@ class NewsCubit extends Cubit<NewsStates>
}
}

List<dynamic> science = [];
List<dynamic>? science = [];

void getScience()
{
emit(NewsGetScienceLoadingState());

if(science.length == 0)
if(science!.isEmpty)
{
DioHelper.getData(
url: 'v2/top-headlines',
Expand All @@ -131,13 +133,13 @@ class NewsCubit extends Cubit<NewsStates>
},
).then((value)
{
//print(value.data['articles'][0]['title']);
//debugPrint(value.data['articles'][0]['title']);
science = value.data['articles'];
print(science[0]['title']);
debugPrint(science![0]['title']);

emit(NewsGetScienceSuccessState());
}).catchError((error){
print(error.toString());
debugPrint(error.toString());
emit(NewsGetScienceErrorState(error.toString()));
});
} else
Expand All @@ -146,7 +148,7 @@ class NewsCubit extends Cubit<NewsStates>
}
}

List<dynamic> search = [];
List<dynamic>? search = [];

void getSearch(String value)
{
Expand All @@ -156,18 +158,18 @@ class NewsCubit extends Cubit<NewsStates>
url: 'v2/everything',
query:
{
'q':'$value',
'q':value,
'apiKey':'65f7f556ec76449fa7dc7c0069f040ca',
},
).then((value)
{
//print(value.data['articles'][0]['title']);
//debugPrint(value.data['articles'][0]['title']);
search = value.data['articles'];
print(search[0]['title']);
debugPrint(search![0]['title']);

emit(NewsGetSearchSuccessState());
}).catchError((error){
print(error.toString());
debugPrint(error.toString());
emit(NewsGetSearchErrorState(error.toString()));
});
}
Expand Down
22 changes: 12 additions & 10 deletions lib/layout/news_app/news_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,37 @@ import 'package:udemy_flutter/shared/components/components.dart';
import 'package:udemy_flutter/shared/cubit/cubit.dart';

class NewsLayout extends StatelessWidget {
const NewsLayout({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return BlocConsumer<NewsCubit, NewsStates>(
listener: (context, state) {},
builder: (context, state)
{
builder: (context, state) {
var cubit = NewsCubit.get(context);

return Scaffold(
appBar: AppBar(
title: Text(
title: const Text(
'News App',
),
actions: [
IconButton(
icon: Icon(
icon: const Icon(
Icons.search,
),
onPressed: ()
{
navigateTo(context, SearchScreen(),);
onPressed: () {
navigateTo(
context,
const SearchScreen(),
);
},
),
IconButton(
icon: Icon(
icon: const Icon(
Icons.brightness_4_outlined,
),
onPressed: ()
{
onPressed: () {
AppCubit.get(context).changeAppMode();
},
),
Expand Down
Loading