forked from zachran-jidlo/zachranobed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing login screen (zachran-jidlo#2)
* Add gradle signing configuration * Add login screen frontend * Introduce constants * Extracting button to custom widget. * Change button color. * Extract text field to custom widget. * Fix overflowing problem on login screen. * Extract clickable text to custom widget. * Introducing checkbox to remember user on login screen * Changing text field style * Adding simple home screen, provider and routing * Adding simple login form validation * Introducing newUser method in user model and unsetting user credentials after logout * Commenting out wrapper for now * Adding form validation error message to constants * Fixing typo in a file name * Introducing wrapper which checks whether the user is already logged in. Co-authored-by: Jakub Timko <[email protected]>
- Loading branch information
Showing
15 changed files
with
786 additions
and
366 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ZachranObedColors { | ||
static const primary = Color.fromRGBO(226, 16, 19, 1); | ||
static const primaryLight = Color.fromRGBO(250, 71, 71, 1); | ||
} | ||
|
||
class ZachranObedStrings { | ||
static const emailAddress = 'E-mailová adresa'; | ||
static const password = 'Heslo'; | ||
static const login = 'Přihlásit se'; | ||
static const forgottenPassword = 'Zapomněl/a jsem heslo'; | ||
static const rememberUser = 'Zapamatovat'; | ||
static const requiredFieldError = 'Vyplňte prosím toto pole'; | ||
|
||
static const zjLogoPath = 'assets/zj-logo.svg'; | ||
static const placeholderImagePath = 'assets/placeholder-image.png'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,26 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
void main() { | ||
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 MaterialApp( | ||
title: 'Flutter Demo', | ||
theme: ThemeData( | ||
// This is the theme of your application. | ||
// | ||
// Try running your application with "flutter run". You'll see the | ||
// application has a blue toolbar. Then, without quitting the app, try | ||
// changing the primarySwatch below to Colors.green and then invoke | ||
// "hot reload" (press "r" in the console where you ran "flutter run", | ||
// or simply save your changes to "hot reload" in a Flutter IDE). | ||
// Notice that the counter didn't reset back to zero; the application | ||
// is not restarted. | ||
primarySwatch: Colors.blue, | ||
), | ||
home: const MyHomePage(title: 'Flutter Demo Home Page'), | ||
); | ||
} | ||
} | ||
|
||
class MyHomePage extends StatefulWidget { | ||
const MyHomePage({super.key, required this.title}); | ||
|
||
// This widget is the home page of your application. It is stateful, meaning | ||
// that it has a State object (defined below) that contains fields that affect | ||
// how it looks. | ||
|
||
// This class is the configuration for the state. It holds the values (in this | ||
// case the title) provided by the parent (in this case the App widget) and | ||
// used by the build method of the State. Fields in a Widget subclass are | ||
// always marked "final". | ||
|
||
final String title; | ||
|
||
@override | ||
State<MyHomePage> createState() => _MyHomePageState(); | ||
} | ||
|
||
class _MyHomePageState extends State<MyHomePage> { | ||
int _counter = 0; | ||
|
||
void _incrementCounter() { | ||
setState(() { | ||
// This call to setState tells the Flutter framework that something has | ||
// changed in this State, which causes it to rerun the build method below | ||
// so that the display can reflect the updated values. If we changed | ||
// _counter without calling setState(), then the build method would not be | ||
// called again, and so nothing would appear to happen. | ||
_counter++; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
// This method is rerun every time setState is called, for instance as done | ||
// by the _incrementCounter method above. | ||
// | ||
// The Flutter framework has been optimized to make rerunning build methods | ||
// fast, so that you can just rebuild anything that needs updating rather | ||
// than having to individually change instances of widgets. | ||
return Scaffold( | ||
appBar: AppBar( | ||
// Here we take the value from the MyHomePage object that was created by | ||
// the App.build method, and use it to set our appbar title. | ||
title: Text(widget.title), | ||
), | ||
body: Center( | ||
// Center is a layout widget. It takes a single child and positions it | ||
// in the middle of the parent. | ||
child: Column( | ||
// Column is also a layout widget. It takes a list of children and | ||
// arranges them vertically. By default, it sizes itself to fit its | ||
// children horizontally, and tries to be as tall as its parent. | ||
// | ||
// Invoke "debug painting" (press "p" in the console, choose the | ||
// "Toggle Debug Paint" action from the Flutter Inspector in Android | ||
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code) | ||
// to see the wireframe for each widget. | ||
// | ||
// Column has various properties to control how it sizes itself and | ||
// how it positions its children. Here we use mainAxisAlignment to | ||
// center the children vertically; the main axis here is the vertical | ||
// axis because Columns are vertical (the cross axis would be | ||
// horizontal). | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
const Text( | ||
'You have pushed the button this many times:', | ||
), | ||
Text( | ||
'$_counter', | ||
style: Theme.of(context).textTheme.headline4, | ||
), | ||
], | ||
), | ||
), | ||
floatingActionButton: FloatingActionButton( | ||
onPressed: _incrementCounter, | ||
tooltip: 'Increment', | ||
child: const Icon(Icons.add), | ||
), // This trailing comma makes auto-formatting nicer for build methods. | ||
); | ||
} | ||
} | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:zachranobed/models/user.dart'; | ||
import 'package:zachranobed/routes.dart'; | ||
|
||
void main() { | ||
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 ChangeNotifierProvider( | ||
create: (context) => User(), | ||
builder: (context, child) { | ||
return const MaterialApp( | ||
initialRoute: RouteManager.wrapper, | ||
onGenerateRoute: RouteManager.generateRoute, | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class User extends ChangeNotifier { | ||
|
||
String email = ""; | ||
String password = ""; | ||
|
||
/*User(this.email, this.password) { | ||
notifyListeners(); | ||
}*/ | ||
|
||
void newUser(String email, String password) { | ||
this.email = email; | ||
this.password = password; | ||
notifyListeners(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:zachranobed/ui/screens/home.dart'; | ||
import 'package:zachranobed/ui/screens/login.dart'; | ||
import 'package:zachranobed/ui/screens/wrapper.dart'; | ||
|
||
class RouteManager { | ||
static const String wrapper = '/'; | ||
static const String login = '/login'; | ||
static const String home = '/home'; | ||
|
||
static Route<dynamic> generateRoute(RouteSettings settings) { | ||
switch (settings.name) { | ||
case wrapper: | ||
return MaterialPageRoute( | ||
builder: (context) => const Wrapper(), | ||
); | ||
|
||
case login: | ||
return MaterialPageRoute( | ||
builder: (context) => const Login(), | ||
); | ||
|
||
case home: | ||
return MaterialPageRoute( | ||
builder: (context) => const Home(), | ||
); | ||
|
||
default: | ||
throw const FormatException('Route not found!'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:zachranobed/models/user.dart'; | ||
import 'package:zachranobed/routes.dart'; | ||
|
||
class Home extends StatelessWidget { | ||
const Home({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text('Home'), | ||
actions: [ | ||
IconButton( | ||
onPressed: () { | ||
Provider.of<User>(context, listen: false).newUser('', ''); | ||
Navigator.of(context).pushReplacementNamed(RouteManager.login); | ||
}, | ||
icon: Icon(Icons.exit_to_app), | ||
), | ||
], | ||
), | ||
body: Center( | ||
child: Consumer<User>( | ||
builder: (context, user, child) { | ||
return Text('Ahoj ${user.email}'); | ||
}, | ||
), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.