From 8783eed93b995b40bca1c469d802012075d1f780 Mon Sep 17 00:00:00 2001 From: Ian B Date: Sat, 14 Oct 2023 23:54:46 -0400 Subject: [PATCH 1/4] Start Clean Up --- app/watt_wizard/lib/homescreen.dart | 105 +++++++++++------- app/watt_wizard/lib/main.dart | 5 +- .../lib/widgets/homes_leaderboard.dart | 21 +++- .../lib/widgets/users_leaderboard.dart | 11 +- 4 files changed, 92 insertions(+), 50 deletions(-) diff --git a/app/watt_wizard/lib/homescreen.dart b/app/watt_wizard/lib/homescreen.dart index 8df6ab5..6945cc2 100644 --- a/app/watt_wizard/lib/homescreen.dart +++ b/app/watt_wizard/lib/homescreen.dart @@ -21,6 +21,35 @@ class _HomeScreenState extends State { BluetoothAdapterState _adapterState = BluetoothAdapterState.unknown; late StreamSubscription _adapterStateStateSubscription; + late String userInput; + + Future _showDialog() async { + return showDialog( + context: context, + barrierDismissible: false, // user must tap button to close dialog + builder: (BuildContext context) { + return AlertDialog( + title: Text('Enter Data'), + content: TextField( + onChanged: (value) { + userInput = value; + }, + decoration: InputDecoration(hintText: "Enter something"), + ), + actions: [ + TextButton( + child: Text('Submit'), + onPressed: () { + makeNewHome(userInput); + Navigator.of(context).pop(); // Close the dialog + }, + ), + ], + ); + }, + ); + } + @override void initState() { user = FirebaseAuth.instance.currentUser!; @@ -59,7 +88,7 @@ class _HomeScreenState extends State { return DefaultTabController( initialIndex: 0, - length: 3, + length: 2, child: Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, @@ -71,7 +100,7 @@ class _HomeScreenState extends State { await FirebaseAuth.instance.signOut(); }, ), - title: const Text("Home Screen"), + title: Text('Welcome, ${user.displayName ?? ""}'), actions: [ IconButton( onPressed: () { @@ -84,52 +113,40 @@ class _HomeScreenState extends State { ], bottom: const TabBar( tabs: [ + // Tab( + // icon: Icon(Icons.cloud_outlined), + // ), Tab( - icon: Icon(Icons.cloud_outlined), - ), - Tab( - icon: Icon(Icons.beach_access_sharp), + icon: Icon(Icons.person), ), Tab( - icon: Icon(Icons.brightness_5_sharp), + icon: Icon(Icons.home), ), ], ), ), body: TabBarView( children: [ - Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - "Welcome ${user.displayName}", - ), - _adapterState == BluetoothAdapterState.on - ? const Spacer() - : FilledButton( - onPressed: () async { - if (Platform.isAndroid) { - await FlutterBluePlus.turnOn(); - } else {} - }, - child: const Text("Turn Bluetooth On"), - ), - // Center( - // child: Column( - // mainAxisAlignment: MainAxisAlignment.center, - // children: [ - // SizedBox( - // width: sizedBoxWidth, - // height: sizedBoxHeight, - // child: UserList(), - // ) - // ], - // ), - // ), - ], - ), - ), + // Center( + // child: Column( + // mainAxisAlignment: MainAxisAlignment.center, + // children: [ + // Text( + // "Welcome ${user.displayName}", + // ), + // _adapterState == BluetoothAdapterState.on + // ? const Spacer() + // : FilledButton( + // onPressed: () async { + // if (Platform.isAndroid) { + // await FlutterBluePlus.turnOn(); + // } else {} + // }, + // child: const Text("Turn Bluetooth On"), + // ), + // ], + // ), + // ), Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, @@ -137,7 +154,7 @@ class _HomeScreenState extends State { SizedBox( width: sizedBoxWidth, height: sizedBoxHeight, - child: UserList(), + child: const UserList(), ) ], ), @@ -148,8 +165,12 @@ class _HomeScreenState extends State { children: [ SizedBox( width: sizedBoxWidth, - height: sizedBoxHeight, - child: HomeList(), + height: sizedBoxHeight - 42, + child: const HomeList(), + ), + ElevatedButton( + onPressed: _showDialog, + child: const Text("Add Home"), ) ], ), diff --git a/app/watt_wizard/lib/main.dart b/app/watt_wizard/lib/main.dart index 3181de0..771d0ea 100644 --- a/app/watt_wizard/lib/main.dart +++ b/app/watt_wizard/lib/main.dart @@ -26,7 +26,10 @@ class MyApp extends StatelessWidget { return MaterialApp( title: 'Watt Wizard', theme: ThemeData( - colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xff9370db)), + colorScheme: ColorScheme.fromSeed( + seedColor: const Color(0xff0abde3), + ), + scaffoldBackgroundColor: const Color(0xff0abde3), useMaterial3: true, ), home: _landingPage(), diff --git a/app/watt_wizard/lib/widgets/homes_leaderboard.dart b/app/watt_wizard/lib/widgets/homes_leaderboard.dart index faf82b5..f7cc3aa 100644 --- a/app/watt_wizard/lib/widgets/homes_leaderboard.dart +++ b/app/watt_wizard/lib/widgets/homes_leaderboard.dart @@ -24,6 +24,14 @@ final _homesRef = _db.collection('homes').withConverter<_Home>( toFirestore: (home, _) => home.toJson(), ); +void makeNewHome(String name) async { + await _db.collection('homes').add({ + 'name': name.substring(0, 30 > name.length ? name.length : 50), + 'pfp': "https://housing.gatech.edu/sites/default/files/styles/building_hero_/public/2022-04/building-at-night.jpeg.jpg", + 'users': [] + }); +} + /// Holds all example app films class HomeList extends StatefulWidget { const HomeList({Key? key}) : super(key: key); @@ -98,9 +106,14 @@ class _HomeItem extends StatelessWidget { /// Returns the movie poster. Widget get pfp { - return SizedBox( - width: 100, - child: Image.network(home.pfp), + return ClipRRect( + borderRadius: BorderRadius.circular(25), + child: Image.network( + home.pfp, + width: 100, + height: 100, + fit: BoxFit.cover, + ), ); } @@ -139,8 +152,8 @@ class _HomeItem extends StatelessWidget { return Padding( padding: const EdgeInsets.only(bottom: 4, top: 4), child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ pfp, Flexible(child: details), diff --git a/app/watt_wizard/lib/widgets/users_leaderboard.dart b/app/watt_wizard/lib/widgets/users_leaderboard.dart index 18dee92..b305dc3 100644 --- a/app/watt_wizard/lib/widgets/users_leaderboard.dart +++ b/app/watt_wizard/lib/widgets/users_leaderboard.dart @@ -74,9 +74,14 @@ class _UserItem extends StatelessWidget { /// Returns the movie poster. Widget get pfp { - return SizedBox( - width: 100, - child: Image.network(user.pfp), + return ClipRRect( + borderRadius: BorderRadius.circular(25), + child: Image.network( + user.pfp, + width: 100, + height: 100, + fit: BoxFit.cover, + ), ); } From becb12f46d9fa8090d0372dd4009e82a39f51e5b Mon Sep 17 00:00:00 2001 From: Ian B Date: Sun, 15 Oct 2023 07:34:47 -0400 Subject: [PATCH 2/4] Color Changes --- app/watt_wizard/lib/homescreen.dart | 1 + .../lib/widgets/homes_leaderboard.dart | 20 ++++++++++++++----- .../lib/widgets/users_leaderboard.dart | 8 ++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/watt_wizard/lib/homescreen.dart b/app/watt_wizard/lib/homescreen.dart index 6945cc2..bff8935 100644 --- a/app/watt_wizard/lib/homescreen.dart +++ b/app/watt_wizard/lib/homescreen.dart @@ -101,6 +101,7 @@ class _HomeScreenState extends State { }, ), title: Text('Welcome, ${user.displayName ?? ""}'), + actions: [ IconButton( onPressed: () { diff --git a/app/watt_wizard/lib/widgets/homes_leaderboard.dart b/app/watt_wizard/lib/widgets/homes_leaderboard.dart index f7cc3aa..e0a4311 100644 --- a/app/watt_wizard/lib/widgets/homes_leaderboard.dart +++ b/app/watt_wizard/lib/widgets/homes_leaderboard.dart @@ -107,7 +107,7 @@ class _HomeItem extends StatelessWidget { /// Returns the movie poster. Widget get pfp { return ClipRRect( - borderRadius: BorderRadius.circular(25), + borderRadius: BorderRadius.circular(15), child: Image.network( home.pfp, width: 100, @@ -131,10 +131,14 @@ class _HomeItem extends StatelessWidget { } // Return the home name. - Widget get name { + Future get name async { return Text( '${home.name}', - style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold), + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + color: home.id == userHome ? Color(0xFF9370db) : Color(0xfff5f5f5), + ), ); } @@ -150,7 +154,7 @@ class _HomeItem extends StatelessWidget { @override Widget build(BuildContext context) { return Padding( - padding: const EdgeInsets.only(bottom: 4, top: 4), + padding: const EdgeInsets.only(bottom: 4, top: 4, left: 8, right: 8), child: Row( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -166,7 +170,12 @@ class _HomeItem extends StatelessWidget { @immutable class _Home { - _Home({required this.pfp, required this.users, required this.name, required this.id}); + _Home({ + required this.pfp, + required this.users, + required this.name, + required this.id, + }); _Home.fromJson(Map json, String id) : this( @@ -188,4 +197,5 @@ class _Home { 'name': name, }; } + } diff --git a/app/watt_wizard/lib/widgets/users_leaderboard.dart b/app/watt_wizard/lib/widgets/users_leaderboard.dart index b305dc3..40c8ac8 100644 --- a/app/watt_wizard/lib/widgets/users_leaderboard.dart +++ b/app/watt_wizard/lib/widgets/users_leaderboard.dart @@ -75,7 +75,7 @@ class _UserItem extends StatelessWidget { /// Returns the movie poster. Widget get pfp { return ClipRRect( - borderRadius: BorderRadius.circular(25), + borderRadius: BorderRadius.circular(15), child: Image.network( user.pfp, width: 100, @@ -103,7 +103,7 @@ class _UserItem extends StatelessWidget { Widget get name { return Text( user.name, - style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold), + style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Color(0xfff5f5f5)), ); } @@ -121,14 +121,14 @@ class _UserItem extends StatelessWidget { return Text( 'Active Power Consumption: ${power.toString()}', - style: const TextStyle(fontSize: 12), + style: const TextStyle(fontSize: 12, color: Color(0xfff5f5f5)), ); } @override Widget build(BuildContext context) { return Padding( - padding: const EdgeInsets.only(bottom: 4, top: 4), + padding: const EdgeInsets.only(bottom: 4, top: 4, left: 8, right: 8), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ From 9983863051d43a372e577dc46fd5cd201ed3a497 Mon Sep 17 00:00:00 2001 From: Shaunak Warty Date: Sun, 15 Oct 2023 07:52:41 -0400 Subject: [PATCH 3/4] WIP --- app/watt_wizard/lib/homescreen.dart | 16 +++---- app/watt_wizard/lib/main.dart | 2 +- .../lib/widgets/homes_leaderboard.dart | 6 +-- .../lib/widgets/users_leaderboard.dart | 45 +++---------------- 4 files changed, 16 insertions(+), 53 deletions(-) diff --git a/app/watt_wizard/lib/homescreen.dart b/app/watt_wizard/lib/homescreen.dart index bff8935..cf13275 100644 --- a/app/watt_wizard/lib/homescreen.dart +++ b/app/watt_wizard/lib/homescreen.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:io'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; @@ -149,15 +148,10 @@ class _HomeScreenState extends State { // ), // ), Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SizedBox( - width: sizedBoxWidth, - height: sizedBoxHeight, - child: const UserList(), - ) - ], + child: SizedBox( + width: sizedBoxWidth, + height: sizedBoxHeight, + child: const UserList(), ), ), Center( @@ -166,7 +160,7 @@ class _HomeScreenState extends State { children: [ SizedBox( width: sizedBoxWidth, - height: sizedBoxHeight - 42, + height: sizedBoxHeight - 45, child: const HomeList(), ), ElevatedButton( diff --git a/app/watt_wizard/lib/main.dart b/app/watt_wizard/lib/main.dart index 771d0ea..08acf22 100644 --- a/app/watt_wizard/lib/main.dart +++ b/app/watt_wizard/lib/main.dart @@ -29,7 +29,7 @@ class MyApp extends StatelessWidget { colorScheme: ColorScheme.fromSeed( seedColor: const Color(0xff0abde3), ), - scaffoldBackgroundColor: const Color(0xff0abde3), + scaffoldBackgroundColor: const Color(0xfff5f5f5), useMaterial3: true, ), home: _landingPage(), diff --git a/app/watt_wizard/lib/widgets/homes_leaderboard.dart b/app/watt_wizard/lib/widgets/homes_leaderboard.dart index e0a4311..2d1b259 100644 --- a/app/watt_wizard/lib/widgets/homes_leaderboard.dart +++ b/app/watt_wizard/lib/widgets/homes_leaderboard.dart @@ -131,13 +131,13 @@ class _HomeItem extends StatelessWidget { } // Return the home name. - Future get name async { + Widget get name { return Text( - '${home.name}', + home.name, style: TextStyle( fontSize: 18, fontWeight: FontWeight.bold, - color: home.id == userHome ? Color(0xFF9370db) : Color(0xfff5f5f5), + color: Color(0xfff5f5f5), ), ); } diff --git a/app/watt_wizard/lib/widgets/users_leaderboard.dart b/app/watt_wizard/lib/widgets/users_leaderboard.dart index 40c8ac8..4ac87b0 100644 --- a/app/watt_wizard/lib/widgets/users_leaderboard.dart +++ b/app/watt_wizard/lib/widgets/users_leaderboard.dart @@ -78,36 +78,13 @@ class _UserItem extends StatelessWidget { borderRadius: BorderRadius.circular(15), child: Image.network( user.pfp, - width: 100, - height: 100, + width: 60, fit: BoxFit.cover, ), ); } - /// Returns user details. - Widget get details { - return Padding( - padding: const EdgeInsets.only(left: 8, right: 8), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - name, - power, - ], - ), - ); - } - - // Return the user name. - Widget get name { - return Text( - user.name, - style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Color(0xfff5f5f5)), - ); - } - - Widget get power { + int get power { int power = 0; for (var i in user.devices) { Map device = i as Map; @@ -119,23 +96,15 @@ class _UserItem extends StatelessWidget { } } - return Text( - 'Active Power Consumption: ${power.toString()}', - style: const TextStyle(fontSize: 12, color: Color(0xfff5f5f5)), - ); + return power; } @override Widget build(BuildContext context) { - return Padding( - padding: const EdgeInsets.only(bottom: 4, top: 4, left: 8, right: 8), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - pfp, - Flexible(child: details), - ], - ), + return ListTile( + leading: pfp, + title: Text(user.name), + subtitle: Text("Active Power Consumption: $power"), ); } } From 6df42a09b504f8a43166764b2dc64129a090a0e4 Mon Sep 17 00:00:00 2001 From: Shaunak Warty Date: Sun, 15 Oct 2023 07:57:23 -0400 Subject: [PATCH 4/4] Update home leaderboard --- .../lib/widgets/homes_leaderboard.dart | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app/watt_wizard/lib/widgets/homes_leaderboard.dart b/app/watt_wizard/lib/widgets/homes_leaderboard.dart index 2d1b259..1522cc6 100644 --- a/app/watt_wizard/lib/widgets/homes_leaderboard.dart +++ b/app/watt_wizard/lib/widgets/homes_leaderboard.dart @@ -110,8 +110,8 @@ class _HomeItem extends StatelessWidget { borderRadius: BorderRadius.circular(15), child: Image.network( home.pfp, - width: 100, - height: 100, + width: 50, + height: 50, fit: BoxFit.cover, ), ); @@ -154,15 +154,11 @@ class _HomeItem extends StatelessWidget { @override Widget build(BuildContext context) { return Padding( - padding: const EdgeInsets.only(bottom: 4, top: 4, left: 8, right: 8), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - pfp, - Flexible(child: details), - updateHomeButton(context, home), - ], + padding: const EdgeInsets.symmetric(vertical: 8), + child: ListTile( + leading: pfp, + title: Text(home.name), + trailing: updateHomeButton(context, home) ), ); }