Skip to content

Instantly share code, notes, and snippets.

@fatihemree
Created June 19, 2020 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fatihemree/1e7c41c232325ae6e2501570bf9b0e41 to your computer and use it in GitHub Desktop.
Save fatihemree/1e7c41c232325ae6e2501570bf9b0e41 to your computer and use it in GitHub Desktop.
class ProductView extends ProductViewModel {
@override
Widget build(BuildContext context) {
return Scaffold(
key: scaffoldKey,
appBar: AppBar(
title: Text("Product List"),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
showModalBottomSheet(
context: context,
builder: (context) => CreateProductView(
onComplete: (model) => onCompleteForm(model),
),
);
},
child: Icon(Icons.add),
),
body: buildFutureBuilder(),
);
}
FutureBuilder<List<ProductModel>> buildFutureBuilder() {
return FutureBuilder<List<ProductModel>>(
future: fetchAllDatas(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.done:
if (snapshot.hasData) return buildListViewWidget(snapshot.data);
return Text("error");
default:
return Center(
child: CircularProgressIndicator(),
);
}
},
);
}
Widget get addMenuWidget => Card(
margin: EdgeInsets.all(15),
child: Form(
child: ListView(
padding: EdgeInsets.all(dynamicHeight(0.05)),
children: <Widget>[
TextFormField(
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: "Product Title",
icon: Icon(Icons.text_fields),
),
),
TextFormField(
decoration: InputDecoration(hintText: "Product Image")),
TextFormField(
inputFormatters: [WhitelistingTextInputFormatter.digitsOnly],
decoration: InputDecoration(hintText: "Product Price")),
FloatingActionButton.extended(
onPressed: () {}, label: Text("Save"))
],
),
),
);
ListView buildListViewWidget(List<ProductModel> data) {
return ListView.builder(
itemBuilder: (context, index) => Card(
child: ListTile(
title: Text(data[index].title),
subtitle: Text("${data[index].weight}g Total: ${data[index].total}"),
leading: Image.network(data[index].image),
trailing: IconButton(
icon: Icon(Icons.edit), onPressed: () => showProductSheet(index)),
),
),
itemCount: data.length,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment