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
1 change: 1 addition & 0 deletions .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences","path":"/Users/shafiqruslan/Documents/FlutterSDK/.pub-cache/hosted/pub.dartlang.org/shared_preferences-2.0.6/","dependencies":[]}],"android":[{"name":"shared_preferences","path":"/Users/shafiqruslan/Documents/FlutterSDK/.pub-cache/hosted/pub.dartlang.org/shared_preferences-2.0.6/","dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"/Users/shafiqruslan/Documents/FlutterSDK/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-2.0.0/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/shafiqruslan/Documents/FlutterSDK/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.0.0/","dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/shafiqruslan/Documents/FlutterSDK/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-2.0.0/","dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"/Users/shafiqruslan/Documents/FlutterSDK/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.0.1/","dependencies":[]},{"name":"shared_preferences_windows","path":"/Users/shafiqruslan/Documents/FlutterSDK/.pub-cache/hosted/pub.dartlang.org/shared_preferences_windows-2.0.0/","dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"/Users/shafiqruslan/Documents/FlutterSDK/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-2.0.0/","dependencies":[]}]},"dependencyGraph":[{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2021-07-01 19:44:53.554537","version":"2.2.2"}
6 changes: 3 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

buildTypes {
Expand All @@ -56,6 +56,6 @@ flutter {

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
8 changes: 8 additions & 0 deletions android/app/local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Thu Jul 01 15:33:13 MYT 2021
sdk.dir=/Users/shafiqruslan/Library/Android/sdk
11 changes: 3 additions & 8 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="flutter_todo"
android:icon="@mipmap/ic_launcher">
<activity
Expand All @@ -17,17 +16,13 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package com.example.flutter_todo;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;

public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}

}
2 changes: 2 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M

1 change: 1 addition & 0 deletions android/settings_aar.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ':app'
13 changes: 8 additions & 5 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/devin/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/devin/Desktop/Sites/flutter-todo"
export "FLUTTER_TARGET=/Users/devin/Desktop/Sites/flutter-todo/lib/main.dart"
export "FLUTTER_ROOT=/Users/shafiqruslan/Documents/FlutterSDK"
export "FLUTTER_APPLICATION_PATH=/Users/shafiqruslan/Documents/FlutterProjects/boilerplate/flutter_todo"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_FRAMEWORK_DIR=/Users/devin/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=0.4.0"
export "FLUTTER_BUILD_NUMBER=0.4.0"
export "TRACK_WIDGET_CREATION=true"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.packages"
7 changes: 3 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:flutter_todo/views/todos.dart';
void main() {
runApp(
ChangeNotifierProvider(
builder: (context) => AuthProvider(),
create: (context) => AuthProvider(),
child: MaterialApp(
initialRoute: '/',
routes: {
Expand All @@ -30,7 +30,6 @@ void main() {
class Router extends StatelessWidget {
@override
Widget build(BuildContext context) {

final authProvider = Provider.of<AuthProvider>(context);

return Consumer<AuthProvider>(
Expand All @@ -42,7 +41,7 @@ class Router extends StatelessWidget {
return LogIn();
case Status.Authenticated:
return ChangeNotifierProvider(
builder: (context) => TodoProvider(authProvider),
create: (context) => TodoProvider(authProvider),
child: Todos(),
);
default:
Expand All @@ -51,4 +50,4 @@ class Router extends StatelessWidget {
},
);
}
}
}
38 changes: 25 additions & 13 deletions lib/providers/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:flutter_todo/widgets/notification_text.dart';
enum Status { Uninitialized, Authenticated, Authenticating, Unauthenticated }

class AuthProvider with ChangeNotifier {

Status _status = Status.Uninitialized;
String _token;
NotificationText _notification;
Expand All @@ -35,14 +34,17 @@ class AuthProvider with ChangeNotifier {
_notification = null;
notifyListeners();

final url = "$api/login";
final url = Uri.parse("$api/login");

Map<String, String> body = {
'email': email,
'password': password,
};

final response = await http.post(url, body: body,);
final response = await http.post(
url,
body: body,
);

if (response.statusCode == 200) {
Map<String, dynamic> apiResponse = json.decode(response.body);
Expand All @@ -66,8 +68,9 @@ class AuthProvider with ChangeNotifier {
return false;
}

Future<Map> register(String name, String email, String password, String passwordConfirm) async {
final url = "$api/register";
Future<Map> register(String name, String email, String password,
String passwordConfirm) async {
final url = Uri.parse("$api/register");

Map<String, String> body = {
'name': name,
Expand All @@ -81,10 +84,15 @@ class AuthProvider with ChangeNotifier {
"message": 'Unknown error.'
};

final response = await http.post( url, body: body, );
final response = await http.post(
url,
body: body,
);

if (response.statusCode == 200) {
_notification = NotificationText('Registration successful, please log in.', type: 'info');
_notification = NotificationText(
'Registration successful, please log in.',
type: 'info');
notifyListeners();
result['success'] = true;
return result;
Expand All @@ -110,16 +118,20 @@ class AuthProvider with ChangeNotifier {
}

Future<bool> passwordReset(String email) async {
final url = "$api/forgot-password";
final url = Uri.parse("$api/forgot-password");

Map<String, String> body = {
'email': email,
};

final response = await http.post( url, body: body, );
final response = await http.post(
url,
body: body,
);

if (response.statusCode == 200) {
_notification = NotificationText('Reset sent. Please check your inbox.', type: 'info');
_notification = NotificationText('Reset sent. Please check your inbox.',
type: 'info');
notifyListeners();
return true;
}
Expand All @@ -142,12 +154,12 @@ class AuthProvider with ChangeNotifier {
logOut([bool tokenExpired = false]) async {
_status = Status.Unauthenticated;
if (tokenExpired == true) {
_notification = NotificationText('Session expired. Please log in again.', type: 'info');
_notification = NotificationText('Session expired. Please log in again.',
type: 'info');
}
notifyListeners();

SharedPreferences storage = await SharedPreferences.getInstance();
await storage.clear();
}

}
}
36 changes: 12 additions & 24 deletions lib/services/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:flutter_todo/utils/todo_response.dart';
import 'package:flutter_todo/models/todo.dart';

class ApiService {

AuthProvider authProvider;
String token;

Expand All @@ -30,26 +29,24 @@ class ApiService {
*/
void validateResponseStatus(int status, int validStatus) {
if (status == 401) {
throw new AuthException( "401", "Unauthorized" );
throw new AuthException("401", "Unauthorized");
}

if (status != validStatus) {
throw new ApiException( status.toString(), "API Error" );
throw new ApiException(status.toString(), "API Error");
}
}

// Returns a list of todos.
Future<TodoResponse> getTodos(String status, { String url = '' }) async {
Future<TodoResponse> getTodos(String status, {String url = ''}) async {
// Defaults to the first page if no url is set.
if ('' == url) {
url = "$api?status=$status";
}

final response = await http.get(
url,
headers: {
HttpHeaders.authorizationHeader: 'Bearer $token'
},
Uri.parse(url),
headers: {HttpHeaders.authorizationHeader: 'Bearer $token'},
);

validateResponseStatus(response.statusCode, 200);
Expand All @@ -71,13 +68,9 @@ class ApiService {
'status': status,
};

final response = await http.patch(
url,
headers: {
HttpHeaders.authorizationHeader: 'Bearer $token'
},
body: body
);
final response = await http.patch(Uri.parse(url),
headers: {HttpHeaders.authorizationHeader: 'Bearer $token'},
body: body);

validateResponseStatus(response.statusCode, 200);
}
Expand All @@ -88,13 +81,9 @@ class ApiService {
'value': text,
};

final response = await http.post(
api,
headers: {
HttpHeaders.authorizationHeader: 'Bearer $token'
},
body: body
);
final response = await http.post(Uri.parse(api),
headers: {HttpHeaders.authorizationHeader: 'Bearer $token'},
body: body);

validateResponseStatus(response.statusCode, 201);

Expand All @@ -103,5 +92,4 @@ class ApiService {
int id = apiResponse['id'];
return id;
}

}
}
6 changes: 2 additions & 4 deletions lib/views/loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import 'package:provider/provider.dart';
import 'package:flutter_todo/providers/auth.dart';

class Loading extends StatelessWidget {

initAuthProvider(context) async {
Provider.of<AuthProvider>(context).initAuthProvider();
Provider.of<AuthProvider>(context, listen: false).initAuthProvider();
}

@override
Widget build(BuildContext context) {

initAuthProvider(context);

return Scaffold(
Expand All @@ -28,4 +26,4 @@ class Loading extends StatelessWidget {
),
);
}
}
}
Loading