Skip to content

Commit

Permalink
- Added back press confirm dialog - Cupertiono style
Browse files Browse the repository at this point in the history
- Added confirmation for delete in add_to_list
- Added screenshots
  • Loading branch information
kashifo committed May 17, 2020
1 parent 0903974 commit e3d0893
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 135 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ This project is created to learn and practice Flutter.
|:-------------------:|:------------------------:|:-----------------:|
| Home Screen | Random Words | Containers |

|![Preview](https://github.com/kashifo/hello_flutter/raw/master/screenshots/friend_list.png) | ![Preview](https://github.com/kashifo/hello_flutter/raw/master/screenshots/add_to_list.png) | ![Preview](https://github.com/kashifo/hello_flutter/raw/master/screenshots/exit_dialog.png) |
|:-------------------:|:------------------------:|:-----------------:|
| Simple List | List: Add & Delete | Exit Dialog |

|![Preview](https://github.com/kashifo/hello_flutter/raw/master/screenshots/biz_card.png) | ![Preview](https://github.com/kashifo/hello_flutter/raw/master/screenshots/dice_app.png) | ![Preview](https://github.com/kashifo/hello_flutter/raw/master/screenshots/xylo.png) |
|:-------------------:|:------------------------:|:-----------------:|
| Business Card | Dice App | Xylophone |
305 changes: 172 additions & 133 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import 'dart:io';

import 'package:Hello_Flutter/biz_card/BizCard.dart';
import 'package:Hello_Flutter/containers.dart';
import 'package:Hello_Flutter/revision/add_to_list.dart';
import 'package:Hello_Flutter/revision/rev_1.dart';
import 'package:Hello_Flutter/simple_list.dart';
import 'package:Hello_Flutter/startup_names.dart';
import 'package:Hello_Flutter/xylophone.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:Hello_Flutter/random_words.dart';

Expand All @@ -19,144 +23,179 @@ void main() {
);
}

class RouteList extends StatelessWidget {
class RouteList extends StatefulWidget {
@override
_RouteListState createState() => _RouteListState();
}

class _RouteListState extends State<RouteList> {
Future<bool> _onWillPop() {
return showDialog(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: Text('Leave the app?'),
content: Text('Are you sure you want to leave the app?'),
actions: <Widget>[
CupertinoDialogAction(
onPressed: () => Navigator.of(context).pop(false),
child: Text('No'),
),
CupertinoDialogAction(
onPressed: () => exit(0),
/*Navigator.of(context).pop(true)*/
child: Text('Yes'),
),
],
);
},
) ??
false;
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: <Widget>[
SizedBox(
height: 20,
),
CircleAvatar(
radius: 40.0,
backgroundImage: AssetImage('images/pp.jpg'),
),
SizedBox(
height: 10,
),
Text(
'Kashif Anwaar',
style: TextStyle(
color: Colors.black,
fontSize: 22,
fontFamily: 'Courgette',
return WillPopScope(
onWillPop: _onWillPop,
child: Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: <Widget>[
SizedBox(
height: 20,
),
),
SizedBox(
height: 1,
),
Text(
'Flutter Developer',
style: TextStyle(
color: Colors.black,
fontSize: 14,
fontFamily: 'CourierPrime',
letterSpacing: 2,
CircleAvatar(
radius: 40.0,
backgroundImage: AssetImage('images/pp.jpg'),
),
),
MyDivider(),
Expanded(
child: ListView(
padding: const EdgeInsets.all(8),
children: <Widget>[
RaisedButton(
child: Text(
'Hello World!',
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HelloFlutter()),
);
},
),
RaisedButton(
child: Text('Random Words'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RandomWordsGen()),
);
},
),
RaisedButton(
child: Text('Containers'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => cellDemo()),
);
},
),
RaisedButton(
child: Text('Simple List'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SimpleList()),
);
},
),
RaisedButton(
child: Text('Infinite List'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => StartupNamesWidget()),
);
},
),
RaisedButton(
child: Text('ListView with Add & Delete'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AddToList()),
);
},
),
RaisedButton(
child: Text('Business Card'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MainBizCard()),
);
},
),
RaisedButton(
child: Text('Dice'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => DiceApp()),
);
},
),
RaisedButton(
child: Text('Xylophone'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => XyloPhone()),
);
},
),
Container(
width: double.infinity,
)
],
SizedBox(
height: 10,
),
Text(
'Kashif Anwaar',
style: TextStyle(
color: Colors.black,
fontSize: 22,
fontFamily: 'Courgette',
),
),
SizedBox(
height: 1,
),
)
],
Text(
'Flutter Developer',
style: TextStyle(
color: Colors.black,
fontSize: 14,
fontFamily: 'CourierPrime',
letterSpacing: 2,
),
),
MyDivider(),
Expanded(
child: ListView(
padding: const EdgeInsets.all(8),
children: <Widget>[
RaisedButton(
child: Text(
'Hello World!',
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HelloFlutter()),
);
},
),
RaisedButton(
child: Text('Random Words'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RandomWordsGen()),
);
},
),
RaisedButton(
child: Text('Containers'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => cellDemo()),
);
},
),
RaisedButton(
child: Text('Simple List'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SimpleList()),
);
},
),
RaisedButton(
child: Text('Infinite List'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => StartupNamesWidget()),
);
},
),
RaisedButton(
child: Text('ListView with Add & Delete'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddToList()),
);
},
),
RaisedButton(
child: Text('Business Card'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MainBizCard()),
);
},
),
RaisedButton(
child: Text('Dice'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => DiceApp()),
);
},
),
RaisedButton(
child: Text('Xylophone'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => XyloPhone()),
);
},
),
Container(
width: double.infinity,
)
],
),
)
],
),
),
),
),
Expand Down
34 changes: 32 additions & 2 deletions lib/revision/add_to_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,31 @@ class _AddToListState extends State<AddToList> {
];
final nameHolder = TextEditingController();

Future<bool> _confirmDelete() {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Delete?'),
content: Text('Are you sure you want to delete'),
actions: <Widget>[
FlatButton(
onPressed: () {
return Navigator.of(context).pop(false);
},
child: Text('No'),
),
FlatButton(
onPressed: () {
return Navigator.of(context).pop(true);
},
child: Text('Yes'),
),
],
),
) ??
false;
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -36,8 +61,13 @@ class _AddToListState extends State<AddToList> {
trailing: IconButton(
icon: Icon(Icons.delete),
onPressed: () {
setState(() {
itemList.removeAt(i);
_confirmDelete().then((isDelete) {
print('_confirmDelete = $isDelete');
if (isDelete) {
setState(() {
itemList.removeAt(i);
});
}
});
},
),
Expand Down
Binary file added screenshots/add_to_list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/exit_dialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed screenshots/home_1.png
Binary file not shown.
Binary file modified screenshots/home_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e3d0893

Please sign in to comment.