From b07ee2aea4ea4801a7e467ca249ffe1630f23c05 Mon Sep 17 00:00:00 2001 From: suresha9 Date: Tue, 6 Dec 2022 16:18:53 +0000 Subject: [PATCH] Final firebase integration along with auth --- expense_tracker/lib/Screens/myhomepage.dart | 1 - expense_tracker/lib/Screens/register.dart | 51 +++++++++ expense_tracker/lib/firebase_options.dart | 64 +++++++++++ expense_tracker/lib/main.dart | 19 ++-- .../Flutter/GeneratedPluginRegistrant.swift | 4 + expense_tracker/pubspec.lock | 102 ++++++++++++++++-- expense_tracker/pubspec.yaml | 7 +- expense_tracker/web/index.html | 30 ------ 8 files changed, 228 insertions(+), 50 deletions(-) create mode 100644 expense_tracker/lib/firebase_options.dart diff --git a/expense_tracker/lib/Screens/myhomepage.dart b/expense_tracker/lib/Screens/myhomepage.dart index c5ecd82..b37b036 100644 --- a/expense_tracker/lib/Screens/myhomepage.dart +++ b/expense_tracker/lib/Screens/myhomepage.dart @@ -21,7 +21,6 @@ class MyHomePage extends StatelessWidget { Navbar(), Padding( padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 40.0), - // child: LandingPage(), ) ], ), diff --git a/expense_tracker/lib/Screens/register.dart b/expense_tracker/lib/Screens/register.dart index 0cf6986..29cff17 100644 --- a/expense_tracker/lib/Screens/register.dart +++ b/expense_tracker/lib/Screens/register.dart @@ -1,8 +1,21 @@ import 'package:flutter/material.dart'; import './myhomepage.dart'; +// import 'package:firebase_auth/firebase_auth.dart' as firebase_auth; class RegisterPage extends StatelessWidget { + const RegisterPage({super.key}); + @override + // _RegisterPageState createState() => _RegisterPageState(); +// } + +// class _RegisterPageState extends State { +// // firebase_auth.FirebaseAuth firebaseAuth = firebase_auth.FirebaseAuth.instance; +// TextEditingController _emailController = TextEditingController(); +// TextEditingController _passwordController = TextEditingController(); +// bool circular = false; + + // @override Widget build(BuildContext context) { return Scaffold( body: SingleChildScrollView( @@ -146,3 +159,41 @@ class RegisterPage extends StatelessWidget { ); } } + + +// Widget textItem(String labeltext, TextEditingController controller, +// bool obscureText, BuildContext context) { +// return SizedBox( +// width: MediaQuery.of(context).size.width - 70, +// height: 55, +// child: TextFormField( +// controller: controller, +// obscureText: obscureText, +// style: const TextStyle( +// fontSize: 17, +// color: Colors.white, +// ), +// decoration: InputDecoration( +// labelText: labeltext, +// labelStyle: const TextStyle( +// fontSize: 17, +// color: Colors.white, +// ), +// focusedBorder: OutlineInputBorder( +// borderRadius: BorderRadius.circular(15), +// borderSide: const BorderSide( +// width: 1.5, +// color: Colors.amber, +// ), +// ), +// enabledBorder: OutlineInputBorder( +// borderRadius: BorderRadius.circular(15), +// borderSide: const BorderSide( +// width: 1, +// color: Colors.grey, +// ), +// ), +// ), +// ), +// ); +// } diff --git a/expense_tracker/lib/firebase_options.dart b/expense_tracker/lib/firebase_options.dart new file mode 100644 index 0000000..2a0475b --- /dev/null +++ b/expense_tracker/lib/firebase_options.dart @@ -0,0 +1,64 @@ +// File generated by FlutterFire CLI. +// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members +import 'package:firebase_core/firebase_core.dart' show FirebaseOptions; +import 'package:flutter/foundation.dart' + show defaultTargetPlatform, kIsWeb, TargetPlatform; + +/// Default [FirebaseOptions] for use with your Firebase apps. +/// +/// Example: +/// ```dart +/// import 'firebase_options.dart'; +/// // ... +/// await Firebase.initializeApp( +/// options: DefaultFirebaseOptions.currentPlatform, +/// ); +/// ``` +class DefaultFirebaseOptions { + static FirebaseOptions get currentPlatform { + if (kIsWeb) { + return web; + } + switch (defaultTargetPlatform) { + case TargetPlatform.android: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for android - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.iOS: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for ios - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.macOS: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for macos - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.windows: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for windows - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.linux: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for linux - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + default: + throw UnsupportedError( + 'DefaultFirebaseOptions are not supported for this platform.', + ); + } + } + + static const FirebaseOptions web = FirebaseOptions( + apiKey: 'AIzaSyBihvrFNZ5rdylgaPqoDANQ6VlsYp32LO0', + appId: '1:839694457195:web:f20f87bbb51fd0934c542e', + messagingSenderId: '839694457195', + projectId: 'expense-tracker-5f15c', + authDomain: 'expense-tracker-5f15c.firebaseapp.com', + storageBucket: 'expense-tracker-5f15c.appspot.com', + measurementId: 'G-MXM3SZ0YTY', + ); +} diff --git a/expense_tracker/lib/main.dart b/expense_tracker/lib/main.dart index f722e89..2809f94 100644 --- a/expense_tracker/lib/main.dart +++ b/expense_tracker/lib/main.dart @@ -1,23 +1,30 @@ -import 'package:expense_tracker/Screens/Login.dart'; +import './Screens/myhomepage.dart'; import 'package:firebase_core/firebase_core.dart'; +import 'firebase_options.dart'; import 'package:flutter/material.dart'; -import 'Screens/Login.dart'; void main() async { - WidgetsFlutterBinding.ensureInitialized(); - await Firebase.initializeApp(); + await Firebase.initializeApp( + options: DefaultFirebaseOptions.currentPlatform, + ); runApp(MyApp()); } -class MyApp extends StatelessWidget { +class MyApp extends StatefulWidget { const MyApp({super.key}); + @override + _MyAppState createState() => _MyAppState(); +} + +class _MyAppState extends State { + // firebase_auth.FirebaseAuth firebaseAuth = firebase_auth.FirebaseAuth.instance; @override Widget build(BuildContext context) { return MaterialApp( title: 'Expense Tracker', theme: ThemeData(primarySwatch: Colors.blue, fontFamily: "Montserrat"), - home: const Login(), + home: const MyHomePage(), ); } } diff --git a/expense_tracker/macos/Flutter/GeneratedPluginRegistrant.swift b/expense_tracker/macos/Flutter/GeneratedPluginRegistrant.swift index 7b9be20..1aa3a57 100644 --- a/expense_tracker/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/expense_tracker/macos/Flutter/GeneratedPluginRegistrant.swift @@ -7,8 +7,12 @@ import Foundation import firebase_auth import firebase_core +import firebase_database +import firebase_storage func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin")) FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin")) + FLTFirebaseDatabasePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseDatabasePlugin")) + FLTFirebaseStoragePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseStoragePlugin")) } diff --git a/expense_tracker/pubspec.lock b/expense_tracker/pubspec.lock index a96d254..cad3b0f 100644 --- a/expense_tracker/pubspec.lock +++ b/expense_tracker/pubspec.lock @@ -1,6 +1,14 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _flutterfire_internals: + dependency: transitive + description: + name: _flutterfire_internals + sha256: e1d4810cd162d842ab1578239a4279a2402d3c1731c1345286df027c830890f8 + url: "https://pub.dev" + source: hosted + version: "1.0.9" async: dependency: transitive description: @@ -33,6 +41,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.1" + cloud_firestore_platform_interface: + dependency: transitive + description: + name: cloud_firestore_platform_interface + sha256: ea3d1d12d72ecaa58909d93e50aca53263d3bf06b904a7f0f1dcd5798941c09b + url: "https://pub.dev" + source: hosted + version: "5.9.0" + cloud_firestore_web: + dependency: transitive + description: + name: cloud_firestore_web + sha256: "3c9a77380e6a053129c2cb6dbe8ef1b708f4350ce0dad220d2c05cd68a2d467f" + url: "https://pub.dev" + source: hosted + version: "3.1.0" collection: dependency: transitive description: @@ -61,34 +85,34 @@ packages: dependency: "direct main" description: name: firebase_auth - sha256: a6ba4b25cbd1bf7847242181eb323b884f4b6c7132280e6fa5f5be63c8048beb + sha256: "806e31185c7bf8089e044c60d08488aa5de5db2a8f8bcf9f8b6a15fd68a274c3" url: "https://pub.dev" source: hosted - version: "1.4.1" + version: "4.1.5" firebase_auth_platform_interface: dependency: transitive description: name: firebase_auth_platform_interface - sha256: bf4dfcd203952dc3be0aa0ec261efe2039f000b5f1b2c9d4934bfaa0ab6c6377 + sha256: "535263a55641e705dba63dc4f412e7c3ad39f9061cbfaf82de640092b53f91f2" url: "https://pub.dev" source: hosted - version: "4.3.1" + version: "6.11.3" firebase_auth_web: dependency: transitive description: name: firebase_auth_web - sha256: "6b753302b88d2b8589a752c85ac561179b6f70094cc5fcbf17d84630c05bddc1" + sha256: "1a7fe4aafed9b29229aa1de6910e0631be94633b4a235e739cc2830a0f110361" url: "https://pub.dev" source: hosted - version: "1.3.1" + version: "5.1.3" firebase_core: dependency: "direct main" description: name: firebase_core - sha256: "4f1d7c13a909e82ff026679c9b8493cdeb35a9c76bc46c42bf9e2240c9e57e80" + sha256: "904bd270364cf4dfaf3c58dc6939c4c7ad26e2877d820dc295ade2cd589d70f3" url: "https://pub.dev" source: hosted - version: "1.24.0" + version: "2.3.0" firebase_core_platform_interface: dependency: transitive description: @@ -101,10 +125,58 @@ packages: dependency: transitive description: name: firebase_core_web - sha256: "839f1b48032a61962792cea1225fae030d4f27163867f181d6d2072dd40acbee" + sha256: a2acf43001a7fcd2997ce6b487b17666077be507d885c9941dd870a16aef3040 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + firebase_database: + dependency: "direct main" + description: + name: firebase_database + sha256: bd8e2b70037e472d25847bb8152374441f54dfbabdc8787f949a47b108046dad + url: "https://pub.dev" + source: hosted + version: "10.0.6" + firebase_database_platform_interface: + dependency: transitive + description: + name: firebase_database_platform_interface + sha256: "3ab1db1f833b78037c069e7a2b983c62f9d4f94f20370cbb143991f581b2e592" + url: "https://pub.dev" + source: hosted + version: "0.2.2+14" + firebase_database_web: + dependency: transitive + description: + name: firebase_database_web + sha256: d399d60cba9574c439094d5755e803eab24231b4093d3cda8c83c5623775b86a url: "https://pub.dev" source: hosted - version: "1.7.3" + version: "0.2.1+16" + firebase_storage: + dependency: "direct main" + description: + name: firebase_storage + sha256: ba654c8b4bbf21e253324769742cfffa66cef9fdce40fc482a677dbe6578c61a + url: "https://pub.dev" + source: hosted + version: "11.0.6" + firebase_storage_platform_interface: + dependency: transitive + description: + name: firebase_storage_platform_interface + sha256: "9dfe3cee7faf9253e1bc2d610644de5c4bc4aa092a7d7ec7e6764f4d453d8149" + url: "https://pub.dev" + source: hosted + version: "4.1.24" + firebase_storage_web: + dependency: transitive + description: + name: firebase_storage_web + sha256: dc095feb0d8cfc5154cf2710ad60ead8a7cafb5ec4f2b20f84c66442e87490f2 + url: "https://pub.dev" + source: hosted + version: "3.3.16" flutter: dependency: "direct main" description: flutter @@ -128,6 +200,14 @@ packages: description: flutter source: sdk version: "0.0.0" + http: + dependency: transitive + description: + name: http + sha256: "6aa2946395183537c8b880962d935877325d6a09a2867c3970c05c0fed6ac482" + url: "https://pub.dev" + source: hosted + version: "0.13.5" http_parser: dependency: transitive description: @@ -271,4 +351,4 @@ packages: version: "2.1.4" sdks: dart: ">=2.19.0-444.0.dev <4.0.0" - flutter: ">=1.12.13+hotfix.5" + flutter: ">=1.20.0" diff --git a/expense_tracker/pubspec.yaml b/expense_tracker/pubspec.yaml index f9ddc5e..682c448 100644 --- a/expense_tracker/pubspec.yaml +++ b/expense_tracker/pubspec.yaml @@ -36,8 +36,11 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 - firebase_core: ^1.0.3 - firebase_auth: ^1.2.0 + firebase_core: ^2.3.0 + firebase_auth: ^4.1.5 + firebase_storage: ^11.0.6 + firebase_database: ^10.0.6 + diff --git a/expense_tracker/web/index.html b/expense_tracker/web/index.html index d93c77d..c29a2e1 100644 --- a/expense_tracker/web/index.html +++ b/expense_tracker/web/index.html @@ -41,36 +41,6 @@ - - - - - - - - - - -