Skip to content

Commit

Permalink
second commit
Browse files Browse the repository at this point in the history
  • Loading branch information
baimamboukar committed Jan 9, 2021
1 parent e60ab53 commit 42ba1b4
Show file tree
Hide file tree
Showing 41 changed files with 1,544 additions and 427 deletions.
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// 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": "electchain",
"request": "launch",
"type": "dart"
}
]
}
10 changes: 8 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
apply plugin: 'com.google.gms.google-services'

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -22,6 +24,7 @@ if (flutterVersionName == null) {
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

Expand All @@ -38,11 +41,12 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.electchain"
minSdkVersion 16
applicationId "com.bravechains.electchain"
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}

buildTypes {
Expand All @@ -60,4 +64,6 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:multidex:1.0.3'
}

39 changes: 39 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"project_info": {
"project_number": "623103710021",
"project_id": "electchain-8ea68",
"storage_bucket": "electchain-8ea68.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:623103710021:android:ad74a9bd02f94be223642c",
"android_client_info": {
"package_name": "com.bravechains.electchain"
}
},
"oauth_client": [
{
"client_id": "623103710021-p6hqpduo0sb1q1s2vkfgr601am4odvoc.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCvm74iYeDPCCIwhrznP-yQrirnB5RAbsI"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "623103710021-p6hqpduo0sb1q1s2vkfgr601am4odvoc.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
8 changes: 8 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.4'
}
}

Expand All @@ -29,3 +30,10 @@ subprojects {
task clean(type: Delete) {
delete rootProject.buildDir
}

buildscript {
dependencies {
// ...
// classpath 'com.google.gms:google-services:4.3.3' // <-- here
}
}
Binary file added assets/icons/bronze.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/gold.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/silver.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/bronze.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/gold.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/silver.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions lib/bidings/add_candidate_binding.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:get/get.dart';
import 'package:Electchain/services/database.dart';
import 'package:Electchain/controllers/controllers.dart';

class AddCandidateBinding extends Bindings {
@override
void dependencies() {
getData() async {
var data;
await DataBase()
.candidatesStream(Get.find<UserController>().user.id,
Get.arguments[0].id.toString())
.then((election) {
data = election.data()['options'];
Get.find<ElectionController>().currentElection.options = data;
});
}
}
}
9 changes: 9 additions & 0 deletions lib/bidings/auth_binding.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:Electchain/controllers/controllers.dart';
import 'package:get/get.dart';

class AuthBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<AuthController>(() => AuthController());
}
}
14 changes: 9 additions & 5 deletions lib/controllers/add_vote_option.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import 'package:Electchain/screens/screens.dart';
import 'package:get/get.dart';
import 'package:Electchain/models/add_vote_option.dart';
import 'package:Electchain/models/models.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class VoteOptionController extends GetxController {
final candidates = List<VoteOption>().obs;
//addOption
addOption(name, desc) {
candidates.add(VoteOption(name: name, description: desc));
class CandidateController extends GetxController {
CandidateModel fromDocumentSnapshot(DocumentSnapshot doc) {
CandidateModel _candidate = CandidateModel();
_candidate.name = doc['name'];
_candidate.description = doc['description'];
return _candidate;
}
}
62 changes: 62 additions & 0 deletions lib/controllers/auth_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import 'package:Electchain/models/models.dart';
import 'package:Electchain/services/database.dart';
import 'package:get/get.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:Electchain/controllers/controllers.dart';

class AuthController extends GetxController {
FirebaseAuth _auth = FirebaseAuth.instance;
Rx<User> _firebaseUser = Rx<User>();
var usercontroller = Get.put(UserController());

String get user => _firebaseUser.value?.email;

@override
// ignore: must_call_super
void onInit() {
_firebaseUser.bindStream(_auth.authStateChanges());
}

void createUser(name, phoneNumber, email, password) async {
try {
var _authResult = await _auth.createUserWithEmailAndPassword(
email: email, password: password);

//Create a user in firestore
UserModel _user = UserModel(
id: _authResult.user.uid,
name: name,
phoneNumber: phoneNumber,
email: email);
if (await DataBase().createNewUser(_user)) {
Get.find<UserController>().user = _user;
Get.back();
}
} catch (err) {
Get.snackbar('Processing Error', err.message);
}
}

void loginUser(String email, String password) async {
try {
var _authResult = await _auth.signInWithEmailAndPassword(
email: email, password: password);

Get.find<UserController>().user =
await DataBase().getUser(_authResult.user.uid);
print(await DataBase().getUser(_authResult.user.uid));
Get.back();
} catch (err) {
Get.snackbar('Processing Error', err.message);
}
}

void signOut() {
try {
_auth.signOut();
Get.find<UserController>().clear();
} catch (err) {
Get.snackbar('Processing Error', err.message);
}
}
}
4 changes: 4 additions & 0 deletions lib/controllers/controllers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export 'add_vote_option.dart';
export 'auth_controller.dart';
export 'user_controller.dart';
export 'election_controller.dart';
47 changes: 47 additions & 0 deletions lib/controllers/election_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'dart:math';

import 'package:Electchain/models/models.dart';
import 'package:Electchain/services/database.dart';
import 'package:get/get.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

//Function to generate the vote access code as a mix of number and sting

const _chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
Random _random = Random();

String getRandomString(int length) => String.fromCharCodes(Iterable.generate(
length, (_) => _chars.codeUnitAt(_random.nextInt(_chars.length))));

class ElectionController extends GetxController {
Rx<ElectionModel> _electionModel = ElectionModel().obs;
ElectionModel currentElection = ElectionModel();

ElectionModel get election => _electionModel.value;

set user(ElectionModel value) => this._electionModel.value = value;

bool endElection() {
_electionModel.value.endDate = DateTime.now().toString();
return true;
}

createElection(name, description, owner, startDate, endDate) {
ElectionModel election = ElectionModel(
accessCode: getRandomString(6),
name: name,
description: description,
owner: owner,
startDate: startDate,
endDate: endDate);
DataBase().createElection(election);
}

candidatesStream(String _uid, String _electionId) {
DataBase().candidatesStream(_uid, _electionId);
}

copyAccessCode() {
//how to copy to the clipboard using dart
}
}
22 changes: 22 additions & 0 deletions lib/controllers/user_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:Electchain/models/models.dart';
import 'package:get/get.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class UserController extends GetxController {
Rx<UserModel> _userModel = UserModel().obs;

UserModel get user => _userModel.value;
set user(UserModel value) => this._userModel.value = value;
void clear() {
_userModel.value = UserModel();
}

UserModel fromDocumentSnapshot(DocumentSnapshot doc) {
UserModel _user = UserModel();
_user.id = doc.id;
_user.email = doc['email'];
_user.name = doc['name'];
_user.phoneNumber = doc['phonenumber'];
return _user;
}
}
Loading

0 comments on commit 42ba1b4

Please sign in to comment.