Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter #20

Merged
merged 4 commits into from
Oct 15, 2023
Merged
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
118 changes: 67 additions & 51 deletions app/watt_wizard/lib/homescreen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:io';

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
Expand All @@ -21,6 +20,35 @@ class _HomeScreenState extends State<HomeScreen> {
BluetoothAdapterState _adapterState = BluetoothAdapterState.unknown;
late StreamSubscription<BluetoothAdapterState> _adapterStateStateSubscription;

late String userInput;

Future<void> _showDialog() async {
return showDialog<void>(
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: <Widget>[
TextButton(
child: Text('Submit'),
onPressed: () {
makeNewHome(userInput);
Navigator.of(context).pop(); // Close the dialog
},
),
],
);
},
);
}

@override
void initState() {
user = FirebaseAuth.instance.currentUser!;
Expand Down Expand Up @@ -59,7 +87,7 @@ class _HomeScreenState extends State<HomeScreen> {

return DefaultTabController(
initialIndex: 0,
length: 3,
length: 2,
child: Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
Expand All @@ -71,7 +99,8 @@ class _HomeScreenState extends State<HomeScreen> {
await FirebaseAuth.instance.signOut();
},
),
title: const Text("Home Screen"),
title: Text('Welcome, ${user.displayName ?? ""}'),

actions: <Widget>[
IconButton(
onPressed: () {
Expand All @@ -84,62 +113,45 @@ class _HomeScreenState extends State<HomeScreen> {
],
bottom: const TabBar(
tabs: <Widget>[
// 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: <Widget>[
// 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: <Widget>[
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: <Widget>[
// SizedBox(
// width: sizedBoxWidth,
// height: sizedBoxHeight,
// child: UserList(),
// )
// ],
// ),
// ),
],
),
),
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
width: sizedBoxWidth,
height: sizedBoxHeight,
child: UserList(),
)
],
child: SizedBox(
width: sizedBoxWidth,
height: sizedBoxHeight,
child: const UserList(),
),
),
Center(
Expand All @@ -148,8 +160,12 @@ class _HomeScreenState extends State<HomeScreen> {
children: <Widget>[
SizedBox(
width: sizedBoxWidth,
height: sizedBoxHeight,
child: HomeList(),
height: sizedBoxHeight - 45,
child: const HomeList(),
),
ElevatedButton(
onPressed: _showDialog,
child: const Text("Add Home"),
)
],
),
Expand Down
5 changes: 4 additions & 1 deletion app/watt_wizard/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(0xfff5f5f5),
useMaterial3: true,
),
home: _landingPage(),
Expand Down
49 changes: 34 additions & 15 deletions app/watt_wizard/lib/widgets/homes_leaderboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(15),
child: Image.network(
home.pfp,
width: 50,
height: 50,
fit: BoxFit.cover,
),
);
}

Expand All @@ -120,8 +133,12 @@ class _HomeItem extends StatelessWidget {
// Return the home name.
Widget get name {
return Text(
'${home.name}',
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
home.name,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xfff5f5f5),
),
);
}

Expand All @@ -137,23 +154,24 @@ class _HomeItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(bottom: 4, top: 4),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
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)
),
);
}
}

@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<String, Object?> json, String id)
: this(
Expand All @@ -175,4 +193,5 @@ class _Home {
'name': name,
};
}

}
50 changes: 12 additions & 38 deletions app/watt_wizard/lib/widgets/users_leaderboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,17 @@ class _UserItem extends StatelessWidget {

/// Returns the movie poster.
Widget get pfp {
return SizedBox(
width: 100,
child: Image.network(user.pfp),
);
}

/// 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 ClipRRect(
borderRadius: BorderRadius.circular(15),
child: Image.network(
user.pfp,
width: 60,
fit: BoxFit.cover,
),
);
}

// Return the user name.
Widget get name {
return Text(
user.name,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
);
}

Widget get power {
int get power {
int power = 0;
for (var i in user.devices) {
Map<String, Object?> device = i as Map<String, Object?>;
Expand All @@ -114,23 +96,15 @@ class _UserItem extends StatelessWidget {
}
}

return Text(
'Active Power Consumption: ${power.toString()}',
style: const TextStyle(fontSize: 12),
);
return power;
}

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(bottom: 4, top: 4),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
pfp,
Flexible(child: details),
],
),
return ListTile(
leading: pfp,
title: Text(user.name),
subtitle: Text("Active Power Consumption: $power"),
);
}
}
Expand Down