Skip to content

Commit e683b2a

Browse files
committed
Merge branch 'feature/new-home' into develop
2 parents f5d311e + fd3934a commit e683b2a

File tree

10 files changed

+271
-124
lines changed

10 files changed

+271
-124
lines changed

lib/core/presentation/pages/home.dart

Lines changed: 36 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import 'package:flutter/material.dart';
77
import 'package:flutter_ui_challenges/core/presentation/pages/favorites.dart';
88
import 'package:flutter_ui_challenges/features/auth/data/model/user_repository.dart';
9-
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
109
import 'package:provider/provider.dart';
1110

1211
import 'main_menu.dart';
@@ -26,70 +25,43 @@ class _HomePageState extends State<HomePage> {
2625

2726
@override
2827
Widget build(BuildContext context) {
29-
return Scaffold(
30-
appBar: PreferredSize(
31-
preferredSize: Size.fromHeight(100),
32-
child: Container(
33-
padding: EdgeInsets.only(top: 30.0),
34-
height: 100,
35-
color: Colors.deepOrange,
36-
child: ListTile(
37-
leading: CircleAvatar(
38-
backgroundColor: Colors.white,
39-
child: Image.asset(
40-
'assets/icon/icon.png',
41-
width: 20,
28+
return Theme(
29+
data: ThemeData(
30+
primarySwatch: Colors.deepOrange,
31+
accentColor: Colors.indigo,
32+
),
33+
child: Scaffold(
34+
appBar: AppBar(
35+
title: Text("UI Challenges"),
36+
),
37+
body: Provider.of<UserRepository>(context).user != null
38+
? _pageIndex == 0 ? MainMenu() : FavoritesTab()
39+
: MainMenu(),
40+
bottomNavigationBar: Provider.of<UserRepository>(context).user == null
41+
? null
42+
: BottomNavigationBar(
43+
selectedItemColor: Theme.of(context).primaryColor,
44+
showUnselectedLabels: false,
45+
showSelectedLabels: false,
46+
backgroundColor: Colors.grey.shade300,
47+
currentIndex: _pageIndex,
48+
onTap: (index) => setState(() {
49+
_pageIndex = index;
50+
}),
51+
items: [
52+
BottomNavigationBarItem(
53+
title: Text(""),
54+
icon: Icon(Icons.home),
4255
),
43-
),
44-
title: Text("Flutter UIs",
45-
style: TextStyle(
46-
color: Colors.white,
47-
fontWeight: FontWeight.bold,
48-
fontSize: 18.0)),
49-
trailing: Row(
50-
mainAxisSize: MainAxisSize.min,
51-
children: <Widget>[
52-
IconButton(
53-
color: Colors.white,
54-
icon: Icon(FontAwesomeIcons.infoCircle),
55-
onPressed: () {
56-
Navigator.pushNamed(context, "about");
57-
},
58-
),
59-
IconButton(
60-
color: Colors.white,
61-
icon: Icon(FontAwesomeIcons.user),
62-
onPressed: () {
63-
(Provider.of<UserRepository>(context).user != null)
64-
? Navigator.pushNamed(context, "profile") : Navigator.pushNamed(context, 'auth_home');
65-
},
66-
),
67-
],
68-
),
69-
),
70-
),
71-
),
72-
body: Provider.of<UserRepository>(context).user != null ? _pageIndex == 0 ? MainMenu() : FavoritesTab() : MainMenu(),
73-
bottomNavigationBar: Provider.of<UserRepository>(context).user == null ? null : BottomNavigationBar(
74-
selectedItemColor: Theme.of(context).primaryColor,
75-
showUnselectedLabels: false,
76-
showSelectedLabels: false,
77-
backgroundColor: Colors.grey.shade300,
78-
currentIndex: _pageIndex,
79-
onTap: (index) => setState((){
80-
_pageIndex = index;
81-
}),
82-
items: [
83-
BottomNavigationBarItem(
84-
title: Text(""),
85-
icon: Icon(Icons.home),
86-
),
87-
BottomNavigationBarItem(
88-
title: Text(""),
89-
icon: Icon( _pageIndex == 1 ? Icons.favorite : Icons.favorite_border),
56+
BottomNavigationBarItem(
57+
title: Text(""),
58+
icon: Icon(_pageIndex == 1
59+
? Icons.favorite
60+
: Icons.favorite_border),
61+
),
62+
],
9063
),
91-
],
92-
),
93-
);
64+
),
65+
);
9466
}
9567
}

lib/core/presentation/pages/main_menu.dart

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@
44
*/
55

66
import 'dart:convert';
7-
import 'package:firebase_remote_config/firebase_remote_config.dart';
87
import 'package:flutter/material.dart';
98
import 'package:flutter_ui_challenges/core/data/favorite_firestore_service.dart';
109
import 'package:flutter_ui_challenges/core/data/models/menu.dart';
11-
import 'package:flutter_ui_challenges/core/data/models/survey.dart';
1210
import 'package:flutter_ui_challenges/core/presentation/widgets/preview.dart';
13-
import 'package:flutter_ui_challenges/core/presentation/widgets/survey_widget.dart';
14-
import 'package:flutter_ui_challenges/features/announcements/data/model/announcement.dart';
15-
import 'package:flutter_ui_challenges/features/announcements/widgets/announcement_slider.dart';
1611
import 'package:flutter_ui_challenges/features/auth/data/model/user.dart';
1712
import 'package:flutter_ui_challenges/features/auth/data/model/user_repository.dart';
1813
import 'package:package_info/package_info.dart';
@@ -26,24 +21,20 @@ class MainMenu extends StatefulWidget {
2621
}
2722

2823
class _MainMenuState extends State<MainMenu> {
29-
RemoteConfig remoteConfig;
3024
Map<String, bool> viewData = <String, bool>{};
31-
List<SubMenuItem> unseen;
3225
bool viewDataLoaded;
26+
List<SubMenuItem> unseen;
3327
bool dialogShowing;
3428
bool showNewUiDialog;
35-
List<Announcement> announcements;
36-
SurveyItem survey;
29+
3730
@override
3831
void initState() {
3932
super.initState();
4033
unseen = [];
4134
viewDataLoaded = false;
4235
dialogShowing = false;
4336
showNewUiDialog = false;
44-
announcements = [];
4537
_getViewData();
46-
_getRemoteConfig();
4738
}
4839

4940
_getViewData() async {
@@ -59,26 +50,6 @@ class _MainMenuState extends State<MainMenu> {
5950
return;
6051
}
6152

62-
_getRemoteConfig() async {
63-
if(remoteConfig == null)
64-
remoteConfig = await RemoteConfig.instance;
65-
final Map<String, dynamic> defaults = {
66-
"news": "[]",
67-
"survey":{},
68-
};
69-
await remoteConfig.setDefaults(defaults);
70-
await remoteConfig.fetch(expiration: const Duration(hours: 12));
71-
await remoteConfig.activateFetched();
72-
final String value = remoteConfig.getString('news');
73-
final String surval = remoteConfig.getString('survey');
74-
setState(() {
75-
announcements = List<Map<String, dynamic>>.from(json.decode(value))
76-
.map((data) => Announcement.fromMap(data))
77-
.toList();
78-
survey = SurveyItem.fromMap(Map<String, dynamic>.from(json.decode(surval)));
79-
});
80-
}
81-
8253
_writeViewData() async {
8354
SharedPreferences prefs = await SharedPreferences.getInstance();
8455
await prefs.setString("page_view_data", json.encode(viewData));
@@ -88,13 +59,10 @@ class _MainMenuState extends State<MainMenu> {
8859
Widget build(BuildContext context) => _buildMenuPage();
8960

9061
ListView _buildMenuPage() {
91-
User user = Provider.of<User>(context);
9262
if (showNewUiDialog && viewDataLoaded) _checkToShowDialog(context);
9363
return ListView(
9464
physics: BouncingScrollPhysics(),
9565
children: <Widget>[
96-
if (announcements.length > 0) AnnouncementSlider(news: announcements),
97-
if(survey != null && user != null && !user.surveys.contains(survey?.id)) SurveyWidget(survey: survey),
9866
...pages.map((page) => page is MenuItem
9967
? _buildExpandableMenu(page, context)
10068
: _buildSubMenu(page, context))
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import 'package:flutter/material.dart';
2+
3+
PreferredSize customAppBar({@required BuildContext context}) {
4+
return PreferredSize(
5+
preferredSize: Size.fromHeight(100),
6+
child: Container(
7+
height: kToolbarHeight+20,
8+
child: ListTile(
9+
contentPadding: const EdgeInsets.all(0),
10+
trailing: Container(
11+
decoration: BoxDecoration(
12+
color: Colors.white,
13+
borderRadius: BorderRadius.only(
14+
bottomLeft: Radius.circular(10.0),
15+
)),
16+
padding: const EdgeInsets.fromLTRB(8.0, 30.0, 8.0, 8.0),
17+
child: Image.asset(
18+
'assets/icon/icon.png',
19+
width: 20,
20+
),
21+
),
22+
title: Padding(
23+
padding: const EdgeInsets.only(top: 35.0, left: 16.0,),
24+
child: Text("Flutter UIs",
25+
style: TextStyle(
26+
color: Theme.of(context).primaryColor,
27+
fontWeight: FontWeight.bold,
28+
fontSize: 18.0)),
29+
),
30+
),
31+
),
32+
);
33+
}

lib/core/presentation/widgets/survey_widget.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ class SurveyWidget extends StatelessWidget {
1313
@override
1414
Widget build(BuildContext context) {
1515
return Container(
16-
color: Theme.of(context).primaryColor,
1716
child: Card(
18-
margin: const EdgeInsets.all(8.0),
17+
elevation: 0,
18+
margin: const EdgeInsets.all(0),
19+
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
1920
child: Padding(
2021
padding: const EdgeInsets.all(16.0),
2122
child: Column(

lib/features/announcements/widgets/announcement_slider.dart

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,25 @@ class AnnouncementSlider extends StatelessWidget {
2020
@override
2121
Widget build(BuildContext context) {
2222
return Container(
23-
height: 140,
24-
color: Theme.of(context).primaryColor,
25-
child: Card(
26-
margin: const EdgeInsets.all(8.0),
27-
child: Swiper(
28-
itemHeight: 120,
29-
itemCount: news.length,
30-
itemBuilder: (context, index) {
31-
Announcement newsItem = news[index];
32-
return AnnouncementListItem(announcement: newsItem);
33-
},
34-
pagination: SwiperPagination(
35-
builder: DotSwiperPaginationBuilder(
36-
color: Colors.grey,
37-
),
38-
),
39-
),
23+
height: 170,
24+
// color: Theme.of(context).primaryColor,
25+
child: Swiper(
26+
viewportFraction: 0.8,
27+
itemHeight: 120,
28+
itemCount: news.length,
29+
loop: false,
30+
itemBuilder: (context, index) {
31+
Announcement newsItem = news[index];
32+
return Padding(
33+
padding: const EdgeInsets.all(8.0),
34+
child: Card(
35+
elevation: 0,
36+
shape: RoundedRectangleBorder(
37+
borderRadius: BorderRadius.circular(10.0)),
38+
margin: const EdgeInsets.all(0),
39+
child: AnnouncementListItem(announcement: newsItem)),
40+
);
41+
},
4042
),
4143
);
4244
}

lib/features/auth/presentation/pages/home.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter_ui_challenges/core/presentation/pages/home.dart';
22
import 'package:flutter_ui_challenges/features/auth/data/model/user_repository.dart';
33
import 'package:flutter/material.dart';
4+
import 'package:flutter_ui_challenges/features/home/presentation/pages/new_home.dart';
45
import 'package:provider/provider.dart';
56
import './splash.dart';
67
import './login.dart';
@@ -17,7 +18,7 @@ class AuthHomePage extends StatelessWidget {
1718
case Status.Authenticating:
1819
return LoginPage();
1920
case Status.Authenticated:
20-
return HomePage();
21+
return NewHomePage();
2122
}
2223
},
2324
);

lib/features/auth/presentation/pages/login.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ class _LoginPageState extends State<LoginPage> {
7373
await prefs.setBool('login_skipped', true);
7474
Navigator.pushNamedAndRemoveUntil(
7575
context,
76-
'home',
77-
ModalRoute.withName('home'),
76+
'/',
77+
ModalRoute.withName('/'),
7878
);
7979
},
8080
),

lib/features/auth/presentation/pages/profile_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ProfileInfo extends StatelessWidget {
6666
color: Theme.of(context).accentColor,
6767
icon: Icon(Icons.exit_to_app),
6868
onPressed: () {
69-
Navigator.pushNamedAndRemoveUntil(context, 'home', ModalRoute.withName('home'));
69+
Navigator.pushNamedAndRemoveUntil(context, '/', ModalRoute.withName('/'));
7070
Provider.of<UserRepository>(context).signOut();
7171
},
7272
)

0 commit comments

Comments
 (0)