Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #214: Side Nav Implementation [WIP] #215

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 103 additions & 21 deletions lib/screens/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:iit_app/screens/home/floating_action_button.dart';
import 'package:iit_app/screens/home/home_widgets.dart';
import 'package:iit_app/screens/home/search_workshop.dart';
import 'package:iit_app/screens/drawer.dart';
import 'package:iit_app/screens/home/side_nav.dart';
import 'package:iit_app/ui/colorPicker.dart';

class HomeScreen extends StatefulWidget {
Expand Down Expand Up @@ -211,6 +212,8 @@ class _HomeScreenState extends State<HomeScreen>
}
}

int currentTab = 0;

@override
Widget build(BuildContext context) {
return WillPopScope(
Expand All @@ -226,8 +229,8 @@ class _HomeScreenState extends State<HomeScreen>
backgroundColor: ColorConstants.homeBackground,
drawer: SideBar(context: context),
floatingActionButton: homeFAB(context, fabKey: fabKey),
appBar: homeAppBar(context,
searchBarWidget: searchBarWidget, fabKey: fabKey),
// appBar: homeAppBar(context,
// searchBarWidget: searchBarWidget, fabKey: fabKey),
body: GestureDetector(
onTap: () {
if (fabKey.currentState.isOpen) {
Expand All @@ -236,29 +239,37 @@ class _HomeScreenState extends State<HomeScreen>
},
child: Stack(
children: [
Container(
margin: EdgeInsets.fromLTRB(12, 10, 12, 0),
decoration: BoxDecoration(
color: ColorConstants.workshopContainerBackground,
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(40.0),
topRight: const Radius.circular(40.0))),
child: ValueListenableBuilder(
valueListenable: searchListener,
builder: (context, isSearching, child) {
return HomeChild(
context: context,
searchBarWidget: searchBarWidget,
tabController: _tabController,
isSearching: isSearching,
fabKey: fabKey,
);
},
Align(
alignment: Alignment.centerRight,
child: Container(
width: MediaQuery.of(context).size.width * 0.78,
decoration: BoxDecoration(
color: ColorConstants.workshopContainerBackground,
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(40.0),
topRight: const Radius.circular(40.0))),
child: ValueListenableBuilder(
valueListenable: searchListener,
builder: (context, isSearching, child) {
return HomeChild(
context: context,
searchBarWidget: searchBarWidget,
tabController: _tabController,
isSearching: isSearching,
fabKey: fabKey,
);
},
),
),
),
AppConstants.chooseColorPaletEnabled
? _colorSelectOptionRow(context)
: Container()
: Container(),
CustomPaint(
size: Size(double.infinity, double.infinity),
foregroundPainter: SideNavPainter(),
),
SideNav(fabKey: fabKey),
],
),
),
Expand All @@ -269,3 +280,74 @@ class _HomeScreenState extends State<HomeScreen>
);
}
}

class SideNav extends StatefulWidget {
final GlobalKey<FabCircularMenuState> fabKey;
SideNav({this.fabKey});
@override
_SideNavState createState() => _SideNavState();
}

class _SideNavState extends State<SideNav> {
SideNavRouteItem selected;

@override
void initState() {
super.initState();
selected = screenList.first;
}

@override
Widget build(BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width * 0.3,
margin: EdgeInsets.only(top: MediaQuery.of(context).size.height * 0.13),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(left: 10),
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 35,
child: Icon(
selected.icon,
size: 50,
color: Colors.black,
),
),
),
SizedBox(height: 40),
Flexible(
child: ListView.builder(
itemBuilder: (context, index) {
if (selected.key != screenList.elementAt(index).key)
return Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: Align(
alignment: Alignment.centerLeft,
child: NavBarTile(
screen: screenList.elementAt(index),
onTap: () {
if (widget.fabKey.currentState.isOpen) {
widget.fabKey.currentState.close();
}
//TODO: Making the navigation possible via pushing
// Navigator.of(context).pushNamed("/mess");
selected = screenList.elementAt(index);
setState(() {});
},
),
),
);
else
return Container();
},
itemCount: screenList.length,
),
),
],
),
);
}
}
90 changes: 90 additions & 0 deletions lib/screens/home/side_nav.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import 'package:flutter/material.dart';

class SideNavRouteItem {
Key key;
String name;
IconData icon;
String route;
SideNavRouteItem({this.name, this.icon, this.route}) {
this.key = Key(name);
}
}

final List<SideNavRouteItem> screenList = [
SideNavRouteItem(icon: Icons.home, name: "Home", route: '/home'),
SideNavRouteItem(icon: Icons.person_outline, name: "Profile", route: '/mess'),
SideNavRouteItem(
icon: Icons.notifications, name: "Notification", route: '/home'),
SideNavRouteItem(icon: Icons.search, name: "Search", route: '/home'),
SideNavRouteItem(icon: Icons.star, name: "Favourite", route: '/home'),
];

class NavBarTile extends StatefulWidget {
final Function onTap;
final SideNavRouteItem screen;
NavBarTile({this.onTap, this.screen});
@override
_NavBarTileState createState() => _NavBarTileState();
}

class _NavBarTileState extends State<NavBarTile> {
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(left: 6),
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 22,
child: InkWell(
onTap: widget.onTap,
child: Icon(
widget.screen.icon,
size: 35,
color: Colors.black,
),
),
),
);
}
}

class SideNavPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var rect = Offset.zero & size;

Paint paint = new Paint()
..style = PaintingStyle.fill
..shader = LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
stops: [0.3, 0.7],
colors: [
Color.fromRGBO(207, 38, 138, 1),
Color.fromRGBO(107, 7, 114, 1),
],
).createShader(rect);
double barWidth = size.width * 0.16;
double curveWidth = size.width * 0.30;
double bezierWidth = size.width * 0.19;
double curveHeight = size.height * 0.19;
Path path = Path();
path.lineTo(0, size.height);
path.lineTo(barWidth, size.height);
path.lineTo(barWidth, size.height * 0.33);
path.quadraticBezierTo(
barWidth, size.height * 0.30, bezierWidth, size.height * 0.28);
path.cubicTo(curveWidth, size.height * 0.25, curveWidth, size.height * 0.13,
bezierWidth, size.height * 0.10);
path.quadraticBezierTo(barWidth, size.height * 0.08, barWidth, 0);
path.lineTo(barWidth, 0);
path.close();

canvas.drawPath(path, paint);
}

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}