Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaavc committed Nov 6, 2020
2 parents bd1166d + 35e5b6e commit 4bba794
Show file tree
Hide file tree
Showing 15 changed files with 332 additions and 48 deletions.
11 changes: 11 additions & 0 deletions src/lib/controller/Controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@ import './database/Database.dart';

class Controller {
Database _database;
String _loggedInUserName;
Function _onSessionChange;

Controller(this._database);

void startApp(StatelessWidget app) {
runApp(app);
}

void setLoggedInUserName(String username) {
this._loggedInUserName = username;
if (_onSessionChange != null) _onSessionChange();
}

String getLoggedInUserName() => this._loggedInUserName;

void setOnSessionChange(Function fn) => this._onSessionChange = fn;

Database getDatabase() => _database;
}
21 changes: 17 additions & 4 deletions src/lib/controller/database/MockAdapter.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import 'package:confnect/model/Forum.dart';

import './Database.dart';
import '../../model/User.dart';

class MockAdapter implements Database {
List<User> users = [];
static List<User> _users = [
User("test", "123"),
];

static List<Forum> _forums = [
Forum(_users[0], "Flutter master", "lorem ipsum"),
Forum(_users[0], "password", "zaszaszazsa"),
];

String getAppName() {
return "Confnect";
Expand All @@ -19,14 +28,14 @@ class MockAdapter implements Database {

int register(String fullname, String username, String password) {
if (fullname.isNotEmpty && username.isNotEmpty && password.isNotEmpty) {
for (var user in users) {
for (var user in _users) {
if (user.getUsername() == username) {
print("Return");
return 2;
}
}

users.add(User(username, password));
_users.add(User(username, password));
print("Register success");
return 1;
}
Expand All @@ -35,6 +44,10 @@ class MockAdapter implements Database {
}

List<User> getUsers() {
return users;
return _users;
}

static List<Forum> getForums() {
return _forums;
}
}
4 changes: 2 additions & 2 deletions src/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class Confnect extends StatelessWidget {
theme: ThemeData(
primaryColor: Colors.white,
),
home: pageFactory.createWelcomeScreen(),
//home: pageFactory.createWelcomeScreen(),
home: pageFactory.createHomePage(),
routes: {
AppRouter.LOGIN: (_) => pageFactory.createLoginPage(),
AppRouter.REGISTER: (_) => pageFactory.createRegisterPage(),
AppRouter.USER_START_PAGE: (_) => pageFactory.createUserStartPage(),
},
);
}
Expand Down
20 changes: 20 additions & 0 deletions src/lib/model/Forum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:confnect/model/User.dart';

class Forum {
final User _author;
final String _title;
final String _description;
Forum(this._author, this._title, this._description);

User getAuthor() {
return _author;
}

String getTitle() {
return _title;
}

String getDescription() {
return _description;
}
}
3 changes: 2 additions & 1 deletion src/lib/view/AppRouter.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class AppRouter {
static const LOGIN = '/user-login';
static const WELCOME_SCREEN = '/hello';
static const REGISTER = '/user-register';
static const USER_START_PAGE = '/user-start-page';
static const MAIN_PAGE = '/user-main-page';
}
17 changes: 9 additions & 8 deletions src/lib/view/PageFactory.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import 'package:confnect/view/pages/WelcomeScreen.dart';
import 'package:confnect/view/pages/HomePage.dart';
import 'package:confnect/view/pages/MyHomePage%20copy.dart';
import '../controller/Controller.dart';
import './pages/Register.dart';
import './pages/Login.dart';
import './pages/UserStartPage.dart';
import './pages/UserSection.dart';
import 'package:flutter/material.dart';

class PageFactory {
Controller controller;
PageFactory(this.controller);

Widget createWelcomeScreen() {
return WelcomeScreen(controller);
}

Widget createLoginPage() {
return Login(controller);
}
Expand All @@ -21,7 +18,11 @@ class PageFactory {
return Register(controller);
}

Widget createUserStartPage() {
return UserStartPage(controller);
Widget createHomePage() {
return HomePage(controller);
}

Widget createTestPage() {
return UserSection(controller);
}
}
30 changes: 30 additions & 0 deletions src/lib/view/pages/HomePage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:flutter/material.dart';
import '../Page.dart';
import '../../controller/Controller.dart';
import './WelcomeScreen.dart';
import './UserSection.dart';

class HomePage extends StatefulPage {
HomePage(Controller controller, {Key key}) : super(controller, key: key);

_HomePageState createState() => _HomePageState(super.getController());
}

class _HomePageState extends State<HomePage> {
final Controller _controller;
_HomePageState(this._controller) {
this._controller.setOnSessionChange(this._onSessionChange);
}

void _onSessionChange() {
setState(() {});
}

@override
Widget build(BuildContext context) {
if (this._controller.getLoggedInUserName() == null)
return WelcomeScreen(this._controller);
else
return UserSection(this._controller);
}
}
5 changes: 3 additions & 2 deletions src/lib/view/pages/Login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class _LoginState extends State<Login> {
String username = usernameController.text,
password = passwordController.text;
if (_controller.getDatabase().login(username, password)) {
Navigator.popAndPushNamed(
context, AppRouter.USER_START_PAGE);
_controller.setLoggedInUserName(username);
Navigator.popUntil(context,
ModalRoute.withName(Navigator.defaultRouteName));
} else {
showDialog(
context: context,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:confnect/controller/Controller.dart';
import 'package:confnect/view/Page.dart';
import 'package:flutter/material.dart';

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
class MyHomePage extends StatefulPage {
MyHomePage(Controller controller, {Key key}) : super(controller, key: key);

// 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
Expand All @@ -12,23 +14,18 @@ class MyHomePage extends StatefulWidget {
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;

@override
_MyHomePageState 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++;
});
}

Expand All @@ -44,7 +41,7 @@ class _MyHomePageState extends State<MyHomePage> {
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),
title: Text("Hello user"),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
Expand All @@ -70,7 +67,7 @@ class _MyHomePageState extends State<MyHomePage> {
'You have pushed the button this many times:',
),
Text(
'$_counter',
"ZAS",
style: Theme.of(context).textTheme.headline4,
),
],
Expand Down
3 changes: 2 additions & 1 deletion src/lib/view/pages/Register.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class _RegisterState extends State<Register> {
.getDatabase()
.register(fullname, username, password) ==
1) {
Navigator.popAndPushNamed(context, AppRouter.USER_START_PAGE);
Navigator.popUntil(
context, ModalRoute.withName(Navigator.defaultRouteName));
} else {
//empty values
if (_controller
Expand Down
54 changes: 54 additions & 0 deletions src/lib/view/pages/UserSection.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import 'package:flutter/material.dart';
import '../Page.dart';
import '../../controller/Controller.dart';
import '../widgets/forum/Forums.dart';

class UserSection extends StatefulPage {
UserSection(Controller controller, {Key key}) : super(controller, key: key);

@override
_UserSectionState createState() => _UserSectionState();
}

class _UserSectionState extends State<UserSection> {
int _selectedIndex = 0;

static final List<Widget> _options = [
Forums(),
Text("Search..."),
Text("Profile..."),
];

void _onItemTapped(int idx) {
setState(() {
this._selectedIndex = idx;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: _UserSectionState._options[this._selectedIndex],
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.forum),
label: 'Forums',
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
label: 'Search',
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
label: 'Profile',
),
],
currentIndex: this._selectedIndex,
selectedItemColor: Colors.blue[800],
onTap: this._onItemTapped,
),
);
}
}
21 changes: 0 additions & 21 deletions src/lib/view/pages/UserStartPage.dart

This file was deleted.

17 changes: 17 additions & 0 deletions src/lib/view/widgets/forum/ForumList.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:confnect/controller/database/MockAdapter.dart';
import './ForumTile.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class ForumList extends StatelessWidget {
@override
Widget build(BuildContext context) {
//final Users users = Provider.of(context);
return ListView(
children: [
ForumTile(MockAdapter.getForums()[0]),
ForumTile(MockAdapter.getForums()[1])
],
);
}
}
Loading

0 comments on commit 4bba794

Please sign in to comment.