Initial commit
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mensaappbackend/providers/pageProvider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
await Supabase.initialize(
|
||||
url: "http://192.168.188.29:8000",
|
||||
anonKey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJhbm9uIiwKICAgICJpc3MiOiAic3VwYWJhc2UtZGVtbyIsCiAgICAiaWF0IjogMTY0MTc2OTIwMCwKICAgICJleHAiOiAxNzk5NTM1NjAwCn0.dc_X5iR_VP_qT0zsiyj_I_OZ2T9FtRU2BBNWN8Bu4GE"
|
||||
);
|
||||
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider(
|
||||
create: (context) => PageProvider(),
|
||||
)
|
||||
],
|
||||
child: MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
colorScheme: const ColorScheme(
|
||||
primary: Color.fromRGBO(236, 92, 61, 1),
|
||||
onPrimary: Color.fromRGBO(240, 240, 240, 1),
|
||||
secondary: Color.fromRGBO(203, 203, 203, 1),
|
||||
onSecondary: Color.fromRGBO(60, 60, 60, 1),
|
||||
error: Colors.red,
|
||||
onError: Colors.white,
|
||||
surface: Colors.white,
|
||||
onSurface: Color.fromRGBO(60, 60, 60, 1),
|
||||
brightness: Brightness.light,
|
||||
tertiary: Color.fromRGBO(251, 216, 17, 1),
|
||||
onTertiary: Color.fromRGBO(60, 60, 60, 1)),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHome()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHome extends StatefulWidget {
|
||||
const MyHome({super.key});
|
||||
|
||||
@override
|
||||
State<MyHome> createState() => _MyHomeState();
|
||||
}
|
||||
|
||||
class _MyHomeState extends State<MyHome> {
|
||||
|
||||
bool initial = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
initial = true;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var supabase = Supabase.instance.client;
|
||||
|
||||
if (initial) {
|
||||
initial = false;
|
||||
if (supabase.auth.currentSession == null) {
|
||||
Provider.of<PageProvider>(context, listen: false).selectedPage = 0;
|
||||
print("not logged in");
|
||||
} else if (supabase.auth.currentSession!.isExpired) {
|
||||
Provider.of<PageProvider>(context, listen: false).selectedPage = 0;
|
||||
print("expired");
|
||||
} else {
|
||||
Provider.of<PageProvider>(context, listen: false).selectedPage = 1;
|
||||
print("logged in");
|
||||
}
|
||||
}
|
||||
|
||||
return Consumer<PageProvider>(
|
||||
builder: (context, pageProvider, child) {
|
||||
return pageProvider.pages[pageProvider.selectedPage];
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mensaappbackend/modules/ratingStars.dart';
|
||||
|
||||
class RatingCard extends StatelessWidget {
|
||||
const RatingCard(
|
||||
{super.key,
|
||||
required this.rating1,
|
||||
required this.rating2,
|
||||
required this.text,
|
||||
required this.title,
|
||||
required this.rating1Title,
|
||||
required this.rating2Title});
|
||||
|
||||
final String title;
|
||||
final String rating1Title;
|
||||
final String rating2Title;
|
||||
|
||||
final int rating1;
|
||||
final int rating2;
|
||||
final String text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.5),
|
||||
spreadRadius: 5,
|
||||
blurRadius: 7,
|
||||
offset: Offset(0, 3))
|
||||
]),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(title, style: TextStyle(fontSize: 22),),
|
||||
SizedBox(height: 10,),
|
||||
Text("$rating1Title:", style: TextStyle(fontSize: 18),),
|
||||
RatingStars(initRating: rating1.toDouble()),
|
||||
SizedBox(height: 10,),
|
||||
Text("$rating2Title:", style: TextStyle(fontSize: 18),),
|
||||
RatingStars(initRating: rating2.toDouble()),
|
||||
SizedBox(height: 10,),
|
||||
Text(text, style: TextStyle(fontSize: 18),)
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
||||
|
||||
class RatingStars extends StatelessWidget {
|
||||
const RatingStars({super.key, required this.initRating});
|
||||
|
||||
final double initRating;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RatingBar.builder(
|
||||
initialRating: initRating,
|
||||
ignoreGestures: true,
|
||||
minRating: 1,
|
||||
itemSize: 35,
|
||||
direction: Axis.horizontal,
|
||||
allowHalfRating: false,
|
||||
itemCount: 5,
|
||||
itemPadding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
itemBuilder: (context, index) {
|
||||
return Icon(
|
||||
Icons.star_rounded,
|
||||
color: Theme.of(context).colorScheme.tertiary,
|
||||
);
|
||||
},
|
||||
onRatingUpdate: (rating) {
|
||||
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mensaappbackend/modules/ratingCard.dart';
|
||||
import 'package:mensaappbackend/providers/pageProvider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
class PageDashboard extends StatelessWidget {
|
||||
const PageDashboard({super.key});
|
||||
|
||||
Future<List<dynamic>> requestSupaBase7Days() async {
|
||||
var supabase = Supabase.instance.client;
|
||||
var result = await supabase.from("ratings_database").select("ratings");
|
||||
return result;
|
||||
}
|
||||
|
||||
final ratingNames = const {
|
||||
"page1": {"title": "Essen", "q1": "Geschmack", "q2": "Qualität"},
|
||||
"page2": {"title": "Service", "q1": "Undefined", "q2": "Undefined"},
|
||||
"page3": {"title": "Wünsche", "q1": "Undefined", "q2": "Undefined"}
|
||||
};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
title: Text(
|
||||
"Dashboard - Bewertungen",
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.onPrimary),
|
||||
),
|
||||
centerTitle: false,
|
||||
actions: [
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
var supabase = Supabase.instance.client;
|
||||
supabase.auth.signOut();
|
||||
Provider.of<PageProvider>(context, listen: false)
|
||||
.setSelectedPage(0);
|
||||
},
|
||||
label: Text(
|
||||
"Logout",
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.onPrimary),
|
||||
),
|
||||
icon: Icon(
|
||||
Icons.logout,
|
||||
color: Theme.of(context).colorScheme.onPrimary,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
body: FutureBuilder(
|
||||
future: requestSupaBase7Days(),
|
||||
builder: (context, snapshot) {
|
||||
var data = snapshot.data;
|
||||
List<Widget> cards = [];
|
||||
|
||||
if (data == null) {
|
||||
return Center();
|
||||
}
|
||||
|
||||
for (var map in data) {
|
||||
var ratings = map["ratings"];
|
||||
|
||||
for (var key in ratings.keys) {
|
||||
var rating = ratings[key];
|
||||
|
||||
if (rating["q1"] != 0) {
|
||||
cards.add(RatingCard(
|
||||
rating1: rating["q1"],
|
||||
rating2: rating["q2"],
|
||||
text: rating["t1"],
|
||||
title: ratingNames[key]!["title"]!,
|
||||
rating1Title: ratingNames[key]!["q1"]!,
|
||||
rating2Title: ratingNames[key]!["q2"]!,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: Center(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
Text(
|
||||
"Letze 7 Tage:",
|
||||
style: TextStyle(fontSize: 25),
|
||||
),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
for (var card in cards) card
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_login/flutter_login.dart';
|
||||
import 'package:mensaappbackend/providers/pageProvider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
class PageLogin extends StatelessWidget {
|
||||
const PageLogin({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FlutterLogin(
|
||||
title: "Dashboard",
|
||||
hideForgotPasswordButton: true,
|
||||
onSubmitAnimationCompleted: () {
|
||||
Provider.of<PageProvider>(context, listen: false).setSelectedPage(Provider.of<PageProvider>(context, listen: false).selectedPage);
|
||||
},
|
||||
onLogin: (p0) async {
|
||||
var supabase = Supabase.instance.client;
|
||||
try {
|
||||
await supabase.auth.signInWithPassword(
|
||||
email: p0.name,
|
||||
password: p0.password
|
||||
);
|
||||
Provider.of<PageProvider>(context, listen: false).selectedPage = 1;
|
||||
print("correct login");
|
||||
} on Exception catch (_) {
|
||||
Provider.of<PageProvider>(context, listen: false).selectedPage = 2;
|
||||
print("wrong login!");
|
||||
}
|
||||
},
|
||||
onRecoverPassword: (p0) {},
|
||||
theme: LoginTheme(
|
||||
pageColorLight: Theme.of(context).colorScheme.surface,
|
||||
pageColorDark: Theme.of(context).colorScheme.surface,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mensaappbackend/providers/pageProvider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class WrongLogin extends StatelessWidget {
|
||||
const WrongLogin({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Text("Deine Login-Daten sind leider falsch!", style: TextStyle(fontSize: 25),),
|
||||
SizedBox(height: 25,),
|
||||
FilledButton.icon(
|
||||
onPressed: () {
|
||||
Provider.of<PageProvider>(context, listen: false).setSelectedPage(0);
|
||||
},
|
||||
style: const ButtonStyle(padding: WidgetStatePropertyAll(EdgeInsets.all(20))),
|
||||
label: const Text("Erneut versuchen...", style: TextStyle(fontSize: 18),),
|
||||
icon: const Icon(Icons.circle_outlined),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:mensaappbackend/pages/pageDashboard.dart';
|
||||
import 'package:mensaappbackend/pages/pageLogin.dart';
|
||||
import 'package:mensaappbackend/pages/wrongLogin.dart';
|
||||
|
||||
class PageProvider extends ChangeNotifier {
|
||||
var selectedPage = 1;
|
||||
|
||||
var pages = [
|
||||
const PageLogin(),
|
||||
const PageDashboard(),
|
||||
const WrongLogin(),
|
||||
];
|
||||
|
||||
void setSelectedPage(var index) {
|
||||
print("hallo");
|
||||
selectedPage = index;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user