Skip to content

Commit

Permalink
Close drawer on back press
Browse files Browse the repository at this point in the history
  • Loading branch information
harveyjavier committed Oct 31, 2019
1 parent 5033afa commit 9bef966
Showing 1 changed file with 58 additions and 22 deletions.
80 changes: 58 additions & 22 deletions lib/screens/news_feed.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:localstorage/localstorage.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'dart:io';

import 'package:bicolit/utils/uidata.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

import 'package:bicolit/tools/drawer.dart';

class NewsFeed extends StatefulWidget {
Expand All @@ -14,6 +14,24 @@ class NewsFeed extends StatefulWidget {

class _NewsFeedState extends State<NewsFeed> {
final storage = LocalStorage("data");
final RefreshController _refreshController = RefreshController();

GlobalKey<ScaffoldState> _globalKey = GlobalKey();
List<Widget> buildList() {
return List.generate(
15,
(index) => Container(
height: 100,
margin: const EdgeInsets.symmetric(
vertical: 10,
horizontal: 15,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
),
));
}

@override
initState() {
Expand All @@ -26,37 +44,55 @@ class _NewsFeedState extends State<NewsFeed> {
}

Future<bool> _onBack() {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text("Confirm Exit", style: TextStyle(color: Colors.white),),
content: Text("Are sure you want to exit app?", style: TextStyle(color: Colors.white),),
actions: <Widget>[
FlatButton(
child: Text("No", style: TextStyle(color: Colors.white),),
onPressed: () => Navigator.pop(context, false),
),
FlatButton(
child: Text("Yes", style: TextStyle(color: Colors.white),),
onPressed: () => exit(0),
),
],
),
);
if (_globalKey.currentState.isDrawerOpen) {
Navigator.pop(context);
} else {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text("Confirm Exit", style: TextStyle(color: Colors.white),),
content: Text("Are sure you want to exit app?", style: TextStyle(color: Colors.white),),
actions: <Widget>[
FlatButton(
child: Text("No", style: TextStyle(color: Colors.white),),
onPressed: () => Navigator.pop(context, false),
),
FlatButton(
child: Text("Yes", style: TextStyle(color: Colors.white),),
onPressed: () => exit(0),
),
],
),
);
}
}

@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: _onBack,
child: Scaffold(
key: _globalKey,
drawer: AppDrawer(current_screen: "newsFeed"),
appBar: AppBar(
title: Text("NewsFeed"),
title: Text("News Feed"),
centerTitle: true,
),
body: Container(),
//body: Container(),
body: SmartRefresher(
controller: _refreshController,
enablePullDown: true,
onRefresh: () async {
await Future.delayed(Duration(seconds: 1));
_refreshController.refreshCompleted();
},
child: CustomScrollView(
slivers: [
SliverList(delegate: SliverChildListDelegate(buildList()))
],
),
),
),
);
}
}
}

0 comments on commit 9bef966

Please sign in to comment.