Skip to content

Commit

Permalink
- Added Riverpod
Browse files Browse the repository at this point in the history
- Improved Performance
- Added Linting
- And many more fixes
  • Loading branch information
abdulmominsakib committed Oct 20, 2024
1 parent cfd96e5 commit 5a3e80c
Show file tree
Hide file tree
Showing 60 changed files with 1,048 additions and 881 deletions.
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "abohawa",
"request": "launch",
"type": "dart"
},
{
"name": "abohawa (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "abohawa (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}
6 changes: 4 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

android {
namespace = "com.example.abohawa"
namespace = "com.abohawa.bangla"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

Expand All @@ -21,7 +21,7 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.example.abohawa"
applicationId = "com.abohawa.bangla"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
Expand All @@ -35,6 +35,8 @@ android {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.debug
minifyEnabled true
shrinkResources true
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
<application
android:label="abohawa"
android:label="আবহাওয়া"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.abohawa
package com.abohawa.bangla

import io.flutter.embedding.android.FlutterActivity

Expand Down
6 changes: 6 additions & 0 deletions android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
<monochrome android:drawable="@mipmap/ic_launcher_monochrome"/>
</adaptive-icon>
Binary file modified android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.abohawa;
PRODUCT_BUNDLE_IDENTIFIER = com.abohawa.bangla;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand All @@ -384,7 +384,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.abohawa.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = com.abohawa.bangla.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -401,7 +401,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.abohawa.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = com.abohawa.bangla.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
Expand All @@ -416,7 +416,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.example.abohawa.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = com.abohawa.bangla.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
Expand Down Expand Up @@ -547,7 +547,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.abohawa;
PRODUCT_BUNDLE_IDENTIFIER = com.abohawa.bangla;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -569,7 +569,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.abohawa;
PRODUCT_BUNDLE_IDENTIFIER = com.abohawa.bangla;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down
30 changes: 30 additions & 0 deletions lib/components/no_internet_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:flutter/material.dart';

import '../constants/styling.dart';

class NoInternetWidget extends StatelessWidget {
const NoInternetWidget({
super.key,
});

@override
Widget build(BuildContext context) {
return Container(
decoration: homeBoxDecoration(),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.wifi_off, size: 50, color: Colors.white),
SizedBox(height: 10),
Text(
'ইন্টারনেট কানেকশন নেই!',
style: kHeaderTitle.copyWith(fontSize: 30),
textAlign: TextAlign.center,
),
],
),
),
);
}
}
File renamed without changes.
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'views/root.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'views/base/base_widget.dart';

void main() {
runApp(
ProviderScope(
Expand Down
59 changes: 59 additions & 0 deletions lib/providers/connection_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'dart:async';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart';

enum AppConnectionStatus {
loading,
online,
offline,
}

class ConnectionStatusNotifier extends StateNotifier<AppConnectionStatus> {
ConnectionStatusNotifier() : super(AppConnectionStatus.loading) {
_init();
}

late StreamSubscription<List<ConnectivityResult>> _connectivitySubscription;
late StreamSubscription<InternetStatus> _internetCheckerSubscription;

Future<void> _init() async {
_connectivitySubscription =
Connectivity().onConnectivityChanged.listen((_) {
_checkInternetAccess();
});

_internetCheckerSubscription =
InternetConnection().onStatusChange.listen((status) {
state = status == InternetStatus.connected
? AppConnectionStatus.online
: AppConnectionStatus.offline;
});

// Perform initial check
await _checkInternetAccess();
}

Future<void> _checkInternetAccess() async {
try {
final isConnected = await InternetConnection().hasInternetAccess;
state = isConnected
? AppConnectionStatus.online
: AppConnectionStatus.offline;
} catch (e) {
state = AppConnectionStatus.offline;
}
}

@override
void dispose() {
_connectivitySubscription.cancel();
_internetCheckerSubscription.cancel();
super.dispose();
}
}

final connectionStatusProvider =
StateNotifierProvider<ConnectionStatusNotifier, AppConnectionStatus>((ref) {
return ConnectionStatusNotifier();
});
1 change: 1 addition & 0 deletions lib/providers/date_provider.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';

import '../models/date_model.dart';

class DateNotifier extends StateNotifier<List<Date>> {
Expand Down
65 changes: 31 additions & 34 deletions lib/providers/search_provider.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:abohawa/config/app_config.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:geocoding/geocoding.dart';
import '../utils/bd_weather_utils.dart';

import '../data/weather_service.dart';
import '../models/city_model.dart';
import '../utils/bd_weather_utils.dart';

class SearchState {
final City? searchedCity;
Expand All @@ -31,43 +31,40 @@ class SearchState {
}

class SearchNotifier extends StateNotifier<SearchState> {
SearchNotifier() : super(SearchState());
final WeatherService _weatherService;

SearchNotifier(this._weatherService) : super(SearchState());

Future<void> searchWeather(String typedCityName) async {
state = state.copyWith(isLoading: true, noCityAvailable: false);

try {
final response = await http.get(Uri.parse(
'https://api.openweathermap.org/data/2.5/weather?q=$typedCityName&appid=${AppConfig.apiKey}&units=metric'));
final cityWeather =
await _weatherService.getWeatherByCityName(typedCityName);

if (response.statusCode == 200) {
final cityWeather = json.decode(response.body);
final String cityName = cityWeather['name'];
final String weatherDescription =
cityWeather['weather'][0]['description'];
final int temperature = cityWeather['main']['temp'].toInt();
final double windSpeed = cityWeather['wind']['speed'] * 3.6;
final String cityName = cityWeather['name'];
final String weatherDescription =
cityWeather['weather'][0]['description'];
final int temperature = cityWeather['main']['temp'].toInt();
final double windSpeed = cityWeather['wind']['speed'] * 3.6;

String banglaLocation = await _getBanglaLocation(typedCityName);
String banglaLocation = await _getBanglaLocation(typedCityName);

final searchedCity = City(
cityName: banglaLocation.isNotEmpty ? banglaLocation : cityName,
temperature: temperature.toString(),
windSpeed: windSpeed.toStringAsFixed(1),
weatherDesc: BDWeatherUtils.getBanglaDesc(weatherDescription),
iconName: BDWeatherUtils.iconName(weatherDescription),
);
final searchedCity = City(
cityName: banglaLocation.isNotEmpty ? banglaLocation : cityName,
temperature: temperature.toString(),
windSpeed: windSpeed.toStringAsFixed(1),
weatherDesc: BDWeatherUtils.getBanglaDesc(weatherDescription),
iconName: BDWeatherUtils.iconName(weatherDescription),
);

state = state.copyWith(
searchedCity: searchedCity,
isLoading: false,
noCityAvailable: false,
);
} else {
state = state.copyWith(isLoading: false, noCityAvailable: true);
}
state = state.copyWith(
searchedCity: searchedCity,
isLoading: false,
noCityAvailable: false,
);
} catch (e) {
print(e);
debugPrint(e.toString());
state = state.copyWith(isLoading: false, noCityAvailable: true);
}
}
Expand All @@ -78,17 +75,17 @@ class SearchNotifier extends StateNotifier<SearchState> {
List<Placemark> placemarks = await placemarkFromCoordinates(
locations[0].latitude,
locations[0].longitude,
// localeIdentifier: 'bn_BN',
);
return placemarks[0].locality ?? '';
} catch (e) {
print(e);
debugPrint(e.toString());
return '';
}
}
}

final searchProvider =
StateNotifierProvider<SearchNotifier, SearchState>((ref) {
return SearchNotifier();
final weatherService = ref.read(weatherServiceProvider);
return SearchNotifier(weatherService);
});
Loading

0 comments on commit 5a3e80c

Please sign in to comment.