ltx-flutter/ltx_flutter/lib/main.dart

143 lines
4.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:ltx_flutter/pages/tabs_page.dart';
import 'package:ltx_flutter/appwrite/appwrite.dart';
import 'package:ltx_flutter/pages/login_page.dart';
import 'package:provider/provider.dart';
void main() {
runApp(ChangeNotifierProvider(
create: (context) => AuthAPI(),
child: LifetrackerApp(),
));
}
class LifetrackerApp extends StatelessWidget {
final TextStyle baseStyle = TextStyle(fontFamily: "monospace");
@override
Widget build(BuildContext context) {
final value = context.watch<AuthAPI>().status;
print('TOP CHANGE Value changed to: $value!');
return MaterialApp(
title: 'Lifetracker',
theme: ThemeData.from(
colorScheme: ColorScheme.dark(),
),
home: value == AuthStatus.uninitialized
? const Scaffold(
body: Center(child: CircularProgressIndicator()),
)
: value == AuthStatus.authenticated
? const TabsPage()
: LoginPage());
// DefaultTabController(
// length: 3,
// child: Scaffold(
// appBar: AppBar(
// title: Text("Lifetracker"),
// bottom: const TabBar(
// tabs: [
// Tab(icon: Icon(Icons.table_chart_sharp)),
// Tab(icon: Icon(Icons.account_circle_sharp)),
// Tab(icon: Icon(Icons.settings_backup_restore)),
// ],
// ),
// ),
// body: TabBarView(children: [
// TableOrPlaceholder(baseStyle: baseStyle),
// AccountPage(),
// Center(
// child: Text("Database settings"),
// ),
// ])),
// ));
// }
}
}
class AccountPage extends StatefulWidget {
const AccountPage({
super.key,
});
@override
AccountPageState createState() {
return AccountPageState();
}
}
class AccountPageState extends State<AccountPage> {
final _loginFormKey = GlobalKey<FormState>();
String email = "";
String password = "";
void _logIn(context) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Logging in...')),
);
// client.login(email, password);
}
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(30.0),
child: Form(
key: _loginFormKey,
child: Column(
children: [
SizedBox(
width: 250,
child: TextFormField(
obscureText: false,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Email',
),
keyboardType: TextInputType.emailAddress,
onChanged: (value) => setState(() {
email = value;
}),
)),
SizedBox(
height: 20,
),
SizedBox(
width: 250,
child: TextFormField(
obscureText: true,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Password',
),
keyboardType: TextInputType.visiblePassword,
onChanged: (value) => setState(() {
password = value;
}),
)),
SizedBox(
height: 20,
),
ElevatedButton.icon(
onPressed: () {
_logIn(context);
},
icon: Icon(Icons.login),
label: Text("Log in")),
Column(
children: <Widget>[
email.isEmpty ? Text("No data") : Text(email),
SizedBox(
height: 10,
),
password.isEmpty ? Text("No Data") : Text(password),
],
)
],
),
),
);
}
}