Skip to content

Instantly share code, notes, and snippets.

@chabibnr
Created July 30, 2019 07:33
Show Gist options
  • Save chabibnr/a70829ffca852a937c15281311667e64 to your computer and use it in GitHub Desktop.
Save chabibnr/a70829ffca852a937c15281311667e64 to your computer and use it in GitHub Desktop.
Temp Delete view
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:submission_4/database/database_helper.dart';
import 'package:submission_4/page/detail_page.dart';
class FavoriteMenu extends StatefulWidget {
final String foodId;
final String foodName;
final String foodImages;
final String locationPage;
FavoriteMenu({this.foodId, this.foodImages, this.foodName,this.locationPage});
@override
_FavoriteMenuState createState() => _FavoriteMenuState();
}
class _FavoriteMenuState extends State<FavoriteMenu> {
bool _isDelete = false;
@override
Widget build(BuildContext context) {
if(_isDelete){
return Container();
}
return Card(
elevation: 3.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(80), bottomRight: Radius.circular(80)),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_imagesFood(),
_contentFood(),
],
),
);
}
Widget _imagesFood() {
return Container(
child: InkWell(
child: Hero(
tag: widget.foodId,
child: Container(
child: Image(
width: 200,
image: CachedNetworkImageProvider(widget.foodImages),
),
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailScreen(
foodIdD: widget.foodId,
),
),
);
},
),
);
}
Widget _contentFood() {
return Expanded(
child: Container(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
widget.foodName,
style: TextStyle(fontSize: 16, letterSpacing: 2),
),
SizedBox(
height: 35.0,
),
RaisedButton(
color: Colors.red[900],
textColor: Colors.white,
child: Icon(Icons.delete_sweep),
onPressed: () {
widget.locationPage == "Dessert" ? _deleteFavoriteDessert(widget.foodId) : _deleteFavoriteSeafood(widget.foodId);
},
)
],
),
),
),
);
}
void _deleteFavoriteDessert(String idMeal) async {
int result = await DBProvider.db.deleteDessert(idMeal);
if (result != 0) {
_showSnackBar(context, 'Hapus ${widget.foodName} Berhasil');
}
_refreshList();
}
void _deleteFavoriteSeafood(String idMeal) async {
int result = await DBProvider.db.deleteSeafood(idMeal);
if (result != 0) {
_showSnackBar(context, 'Hapus ${widget.foodName} Berhasil');
}
_refreshList();
}
void _showSnackBar(BuildContext context, String message) {
final snackBar = SnackBar(
duration: Duration(seconds: 1),
backgroundColor: Colors.red,
content: Text(message),
);
Scaffold.of(context).showSnackBar(snackBar);
}
void _refreshList() {
setState(() {
_isDelete = true;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment