Skip to content

Commit

Permalink
Add bottom_bar bloc and allow app share
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardo2204 committed May 25, 2020
1 parent 57d54f7 commit d2368a9
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 112 deletions.
111 changes: 60 additions & 51 deletions lib/bloc/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:confs_tech/widgets/main_bottom_bar.dart';
import 'package:confs_tech/widgets/sliver_search_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:share/share.dart';

class HomePage extends StatefulWidget {
@override
Expand All @@ -28,60 +29,68 @@ class _HomePageState extends State<HomePage> {

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: SearchBar(
actions: <Widget>[
PopupMenuButton(
itemBuilder: (context){
return {'Feedback', 'About'}.map((item) =>
PopupMenuItem(
value: item,
child: Text(item),
)
).toList();
},
onSelected: (selected) {
if (selected == 'Feedback') {
Navigator.pushNamed(context, '/feedback');
} else if (selected == 'About') {
showAboutDialog(
context: context,
applicationName: "Confs.tech",
applicationIcon: Image(
image: AssetImage("images/logo_icon.png"),
width: 32,
height: 32,
return BlocProvider(
create: (context) => BottomBarBloc(),
child: Scaffold(
appBar: SearchBar(
actions: <Widget>[
PopupMenuButton(
itemBuilder: (context){
return {'Feedback', 'Share the app', 'About'}.map((item) =>
PopupMenuItem(
value: item,
child: Text(item),
)
).toList();
},
onSelected: (selected) {
if (selected == 'Feedback') {
Navigator.pushNamed(context, '/feedback');
} else if (selected == 'About') {
showAboutDialog(
context: context,
applicationName: "Confs.tech",
applicationIcon: Image(
image: AssetImage("images/logo_icon.png"),
width: 32,
height: 32,
),
applicationVersion: "1.0",
children: [
ConfsAboutDialog.AboutDialog()
]
);
} else if (selected == 'Share the app') {
//CHANGE THE URL TO iOS and Android!!!
Share.share('Hey, check out this conference events app: '
'https://play.google.com/store/apps/details?id=leonardo2204.com.confs_tech');
}
},
)
],
onSearchTextChanged: (text) {
BlocProvider.of<FilteredEventsBloc>(context)
.add(SearchChanged(searchQuery: text));
},
),
body: SafeArea(
child: MultiBlocProvider(
providers: [
BlocProvider(
create: (BuildContext ctx) => _eventBloc
),
BlocProvider(
create: (BuildContext ctx) =>
FilterStatsBloc(
filteredEventsBloc: BlocProvider.of<FilteredEventsBloc>(context)
),
applicationVersion: "1.0",
children: [
ConfsAboutDialog.AboutDialog()
]
);
}
},
)
],
onSearchTextChanged: (text) {
BlocProvider.of<FilteredEventsBloc>(context)
.add(SearchChanged(searchQuery: text));
},
),
body: SafeArea(
child: MultiBlocProvider(
providers: [
BlocProvider(
create: (BuildContext ctx) => _eventBloc
),
BlocProvider(
create: (BuildContext ctx) =>
FilterStatsBloc(
filteredEventsBloc: BlocProvider.of<FilteredEventsBloc>(context)
),
),],
child: SearchBody(),
),
],
child: SearchBody(),
),
),
bottomNavigationBar: MainBottomBar(),
),
bottomNavigationBar: MainBottomBar(),
);
}
}
3 changes: 3 additions & 0 deletions lib/blocs/bloc.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export 'bottom_bar/bottom_bar_bloc.dart';
export 'bottom_bar/bottom_bar_event.dart';
export 'bottom_bar/bottom_bar_state.dart';
export 'event/event_bloc.dart';
export 'event/event_event.dart';
export 'event/event_state.dart';
Expand Down
20 changes: 20 additions & 0 deletions lib/blocs/bottom_bar/bottom_bar_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'dart:async';

import 'package:bloc/bloc.dart';

import '../bloc.dart';


class BottomBarBloc extends Bloc<BottomBarEvent, BottomBarState> {
@override
BottomBarState get initialState => InitialBottomBarState();

@override
Stream<BottomBarState> mapEventToState(
BottomBarEvent event,
) async* {
if (event is BottomBarSelected) {
yield BottomBarSelectedSuccess(selectedIndex: event.selectedIndex);
}
}
}
14 changes: 14 additions & 0 deletions lib/blocs/bottom_bar/bottom_bar_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:equatable/equatable.dart';

abstract class BottomBarEvent extends Equatable {
const BottomBarEvent();
}

class BottomBarSelected extends BottomBarEvent {
final int selectedIndex;

BottomBarSelected(this.selectedIndex);

@override
List<Object> get props => [selectedIndex];
}
19 changes: 19 additions & 0 deletions lib/blocs/bottom_bar/bottom_bar_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:equatable/equatable.dart';

abstract class BottomBarState extends Equatable {
final int selectedIndex;
const BottomBarState({ this.selectedIndex = 0 });
}

class InitialBottomBarState extends BottomBarState {
@override
List<Object> get props => [];
}

class BottomBarSelectedSuccess extends BottomBarState {
BottomBarSelectedSuccess({ selectedIndex = 0 })
: super(selectedIndex: selectedIndex);

@override
List<Object> get props => [selectedIndex];
}
84 changes: 41 additions & 43 deletions lib/widgets/main_bottom_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,49 @@ class MainBottomBar extends StatefulWidget{
}

class _MainBottomBarState extends State<MainBottomBar> {
int selectedIdx = 0;

@override
Widget build(BuildContext context) {
return BottomNavigationBar(
currentIndex: selectedIdx,
onTap: (int selected){
switch (selected) {
case 0:
BlocProvider.of<FilteredEventsBloc>(context)
.add(UpcomingSelected());
setState(() {
selectedIdx = 0;
});
break;
case 1:
BlocProvider.of<FilteredEventsBloc>(context)
.add(CallForPaperSelected());
setState(() {
selectedIdx = 1;
});
break;
case 2:
BlocProvider.of<FilteredEventsBloc>(context)
.add(ShowPastSelected());
setState(() {
selectedIdx = 2;
});
break;
}
},
items: [
BottomNavigationBarItem(
icon: Icon(Icons.event),
title: Text("Upcoming"),
),
BottomNavigationBarItem(
icon: Icon(Icons.note_add),
title: Text("Call for Papers"),
),
BottomNavigationBarItem(
icon: Icon(Icons.event_available),
title: Text("Past"),
)
],
return BlocBuilder<BottomBarBloc, BottomBarState>(
bloc: BlocProvider.of(context),
builder: (context, state) => BottomNavigationBar(
currentIndex: state.selectedIndex,
onTap: (int selected){
switch (selected) {
case 0:
BlocProvider.of<BottomBarBloc>(context)
.add(BottomBarSelected(0));
BlocProvider.of<FilteredEventsBloc>(context)
.add(UpcomingSelected());
break;
case 1:
BlocProvider.of<BottomBarBloc>(context)
.add(BottomBarSelected(1));
BlocProvider.of<FilteredEventsBloc>(context)
.add(CallForPaperSelected());
break;
case 2:
BlocProvider.of<BottomBarBloc>(context)
.add(BottomBarSelected(2));
BlocProvider.of<FilteredEventsBloc>(context)
.add(ShowPastSelected());
break;
}
},
items: [
BottomNavigationBarItem(
icon: Icon(Icons.event),
title: Text("Upcoming"),
),
BottomNavigationBarItem(
icon: Icon(Icons.note_add),
title: Text("Call for Papers"),
),
BottomNavigationBarItem(
icon: Icon(Icons.event_available),
title: Text("Past"),
)
],
),
);
}

Expand Down
43 changes: 26 additions & 17 deletions lib/widgets/sliver_search_bar.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:confs_tech/blocs/bloc.dart';
import 'package:confs_tech/widgets/ellipsis_painter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class SearchBar extends StatefulWidget implements PreferredSizeWidget {
final List<Widget> actions;
Expand Down Expand Up @@ -75,24 +77,31 @@ class _SearchBarState extends State<SearchBar> with SingleTickerProviderStateMix
},
child: Stack(
children: [
AppBar(
backgroundColor: isInSearchMode ?
Colors.white : Theme.of(context).primaryColor,
title: _appBarTitle,
leading: isInSearchMode ? IconButton(
icon: Icon(Icons.arrow_back),
onPressed: _toggleAppBarStatus,
) : null,
actions: List.unmodifiable(() sync* {
if (!isInSearchMode) yield
GestureDetector(
child: Icon(Icons.search),
onTapUp: onSearchTapUp,
);
if (!isInSearchMode && this.actions != null) {
yield* this.actions;
BlocListener<BottomBarBloc, BottomBarState>(
listener: (BuildContext context, BottomBarState state) {
if (state is BottomBarSelectedSuccess && isInSearchMode) {
_toggleAppBarStatus();
}
}()),
},
child: AppBar(
backgroundColor: isInSearchMode ?
Colors.white : Theme.of(context).primaryColor,
title: _appBarTitle,
leading: isInSearchMode ? IconButton(
icon: Icon(Icons.arrow_back),
onPressed: _toggleAppBarStatus,
) : null,
actions: List.unmodifiable(() sync* {
if (!isInSearchMode) yield
GestureDetector(
child: Icon(Icons.search),
onTapUp: onSearchTapUp,
);
if (!isInSearchMode && this.actions != null) {
yield* this.actions;
}
}()),
),
),
!isInSearchMode ? AnimatedBuilder(
animation: _animation,
Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.24.0"
share:
dependency: "direct main"
description:
name: share
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.4+3"
sky_engine:
dependency: transitive
description: flutter
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: Find your next conference
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+3
version: 1.0.1+0

environment:
sdk: ">=2.2.0 <3.0.0"
Expand All @@ -28,6 +28,7 @@ dependencies:
intl: ^0.16.1
url_launcher: ^5.4.2
collection: ^1.14.11
share: ^0.6.4+3

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
Expand Down

0 comments on commit d2368a9

Please sign in to comment.