Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:flutter_svg/svg.dart';
- import 'dart:convert';
- import 'package:http/http.dart' as http;
- import 'ItemListViewScreen.dart';
- import 'SideDrawerScreen.dart';
- import 'Utils/Constants.dart';
- import 'Utils/SharedPrefrence.dart';
- import 'Utils/Urls.dart';
- ///CategoryItem model class
- CategoryItemModel categoryItemModelFromJson(String str) =>
- CategoryItemModel.fromJson(json.decode(str));
- String categoryItemModelToJson(CategoryItemModel data) =>
- json.encode(data.toJson());
- class CategoryItemModel {
- CategoryItemModel({
- this.success,
- this.message,
- this.data,
- });
- bool success;
- String message;
- Data data;
- factory CategoryItemModel.fromJson(Map<String, dynamic> json) =>
- CategoryItemModel(
- success: json["success"],
- message: json["message"],
- data: Data.fromJson(json["data"]),
- );
- Map<String, dynamic> toJson() => {
- "success": success,
- "message": message,
- "data": data.toJson(),
- };
- }
- class Data {
- Data({
- this.customTags,
- this.userTags,
- });
- List<CustomTag> customTags;
- List<UserTag> userTags;
- factory Data.fromJson(Map<String, dynamic> json) => Data(
- customTags: List<CustomTag>.from(
- json["custom_tags"].map((x) => CustomTag.fromJson(x))),
- userTags: List<UserTag>.from(
- json["user_tags"].map((x) => UserTag.fromJson(x))),
- );
- Map<String, dynamic> toJson() => {
- "custom_tags": List<dynamic>.from(customTags.map((x) => x.toJson())),
- "user_tags": List<dynamic>.from(userTags.map((x) => x.toJson())),
- };
- }
- class CustomTag {
- CustomTag({
- this.id,
- this.userId,
- this.name,
- this.deletedAt,
- this.createdAt,
- this.updatedAt,
- });
- int id;
- int userId;
- String name;
- dynamic deletedAt;
- DateTime createdAt;
- DateTime updatedAt;
- factory CustomTag.fromJson(Map<String, dynamic> json) => CustomTag(
- id: json["id"],
- userId: json["user_id"],
- name: json["name"],
- deletedAt: json["deleted_at"],
- createdAt: DateTime.parse(json["created_at"]),
- updatedAt: DateTime.parse(json["updated_at"]),
- );
- Map<String, dynamic> toJson() => {
- "id": id,
- "user_id": userId,
- "name": name,
- "deleted_at": deletedAt,
- "created_at": createdAt.toIso8601String(),
- "updated_at": updatedAt.toIso8601String(),
- };
- }
- class UserTag {
- UserTag({
- this.id,
- this.name,
- this.slug,
- this.icon,
- this.thumbs,
- this.createdAt,
- this.updatedAt,
- this.tags,
- this.translated,
- });
- int id;
- String name;
- String slug;
- String icon;
- ThumbsClass thumbs;
- DateTime createdAt;
- DateTime updatedAt;
- List<Tag> tags;
- dynamic translated;
- factory UserTag.fromJson(Map<String, dynamic> json) => UserTag(
- id: json["id"],
- name: json["name"],
- slug: json["slug"],
- icon: json["icon"],
- thumbs: ThumbsClass.fromJson(json["thumbs"]),
- createdAt: DateTime.parse(json["created_at"]),
- updatedAt: DateTime.parse(json["updated_at"]),
- tags: List<Tag>.from(json["tags"].map((x) => Tag.fromJson(x))),
- translated: json["translated"],
- );
- Map<String, dynamic> toJson() => {
- "id": id,
- "name": name,
- "slug": slug,
- "icon": icon,
- "thumbs": thumbs.toJson(),
- "created_at": createdAt.toIso8601String(),
- "updated_at": updatedAt.toIso8601String(),
- "tags": List<dynamic>.from(tags.map((x) => x.toJson())),
- "translated": translated,
- };
- }
- class Tag {
- Tag({
- this.id,
- this.slug,
- this.name,
- this.icon,
- this.thumbs,
- this.tagCategoryId,
- this.createdAt,
- this.updatedAt,
- this.flyerItemsCount,
- this.translated,
- });
- int id;
- String slug;
- String name;
- String icon;
- dynamic thumbs;
- int tagCategoryId;
- DateTime createdAt;
- DateTime updatedAt;
- int flyerItemsCount;
- dynamic translated;
- factory Tag.fromJson(Map<String, dynamic> json) => Tag(
- id: json["id"],
- slug: json["slug"],
- name: json["name"],
- icon: json["icon"],
- thumbs: json["thumbs"],
- tagCategoryId: json["tag_category_id"],
- createdAt: DateTime.parse(json["created_at"]),
- updatedAt: DateTime.parse(json["updated_at"]),
- flyerItemsCount: json["flyer_items_count"],
- translated: json["translated"],
- );
- Map<String, dynamic> toJson() => {
- "id": id,
- "slug": slug,
- "name": name,
- "icon": icon,
- "thumbs": thumbs,
- "tag_category_id": tagCategoryId,
- "created_at": createdAt.toIso8601String(),
- "updated_at": updatedAt.toIso8601String(),
- "flyer_items_count": flyerItemsCount,
- "translated": translated,
- };
- }
- class ThumbsClass {
- ThumbsClass({
- this.lg,
- this.md,
- this.sm,
- this.xs,
- });
- String lg;
- String md;
- String sm;
- String xs;
- factory ThumbsClass.fromJson(Map<String, dynamic> json) => ThumbsClass(
- lg: json["lg"],
- md: json["md"],
- sm: json["sm"],
- xs: json["xs"],
- );
- Map<String, dynamic> toJson() => {
- "lg": lg,
- "md": md,
- "sm": sm,
- "xs": xs,
- };
- }
- ///End of CategoryItem model class
- ///Listview Design
- class DashboardItemListScreen extends StatefulWidget {
- @override
- _DashboardItemListScreenState createState() =>
- _DashboardItemListScreenState();
- }
- class _DashboardItemListScreenState extends State<DashboardItemListScreen> {
- bool _isChecked = false;
- List<bool> inputs = new List<bool>();
- String userToken;
- final _scaffoldKey = GlobalKey<ScaffoldState>();
- // List<CategoryItemModel> categoryItemModel = [];
- CategoryItemModel categoryItemModel;
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- Future token = SharedPrefrence().getToken();
- token.then((data) async {
- userToken = data;
- getCategoryLists();
- });
- // getCategoryLists();
- setState(() {
- for (int i = 0; i < 4; i++) {
- inputs.add(false);
- }
- });
- }
- void ItemChange(bool val, int index) {
- setState(() {
- inputs[index] = val;
- });
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- key: _scaffoldKey,
- resizeToAvoidBottomInset: false,
- drawer: SideDraweScreen(),
- appBar: AppBar(
- iconTheme: new IconThemeData(color: Color.fromRGBO(34, 83, 148, 1)),
- title: appbarLogo(),
- backgroundColor: Colors.white,
- actions: [
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: Icon(
- Icons.shopping_cart,
- color: Colors.blue[800],
- ),
- )
- ],
- ),
- body: SingleChildScrollView(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Expanded(
- flex: 0,
- child: Container(
- height: 30,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: Text(
- "Select All",
- softWrap: true,
- style: TextStyle(color: Colors.blue[500], fontSize: 15),
- ),
- ),
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: Icon(
- Icons.delete,
- color: Colors.blue[500],
- size: 20,
- ),
- ),
- ],
- ),
- ),
- ),
- Expanded(
- flex: 0,
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Text(
- "Shopping List",
- softWrap: true,
- style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
- ),
- ),
- ),
- Expanded(flex: 0, child: Categories()),
- ],
- ),
- ),
- floatingActionButton: new FloatingActionButton(
- onPressed: () {
- PopupCategory(context);
- },
- child: const Icon(
- Icons.add,
- ),
- ),
- );
- }
- Widget appbarLogo() {
- return SvgPicture.asset("assets/images/flyerbin_logo.svg",height: 40,);
- }
- Widget Categories() {
- Size size = MediaQuery.of(context).size;
- return categoryItemModel == null
- ? Center(child: CircularProgressIndicator())
- : Container(
- child: Column(
- children: [
- Expanded(
- flex: 0,
- child: Padding(
- padding: const EdgeInsets.all(2),
- child: Card(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Expanded(
- flex: 0,
- child: Container(
- width: 220,
- child: CheckboxListTile(
- controlAffinity: ListTileControlAffinity.leading,
- title: _isChecked !=false ? Text('Tee', style: TextStyle(decoration: TextDecoration.lineThrough)):Text("Tee"),
- value: _isChecked,
- onChanged: (bool value) {
- setState(() {
- _isChecked = value;
- });
- },
- ),
- ),
- ),
- Expanded(
- flex: 0,
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Icon(
- Icons.cancel,
- size: 20,
- color: Colors.blueGrey,
- ),
- ))
- ],
- ),
- ),
- ),
- ),
- ListView.builder(
- shrinkWrap: true,
- physics: NeverScrollableScrollPhysics(),
- itemBuilder: (context, index) {
- return Padding(
- padding: EdgeInsets.all(2),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: Text(
- '${categoryItemModel.data.userTags[index].name}',
- style: TextStyle(
- fontSize: 15, fontWeight: FontWeight.bold),
- ),
- ),
- ListView.builder(
- shrinkWrap: true,
- physics: ClampingScrollPhysics(),
- itemBuilder: (context, index1) {
- return Card(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Expanded(
- flex: 0,
- child: Container(
- width: 220,
- child: CheckboxListTile(
- controlAffinity:
- ListTileControlAffinity.leading,
- title: _isChecked !=false ? Text('${categoryItemModel.data.userTags[index].tags[index1].name}', style: TextStyle(decoration: TextDecoration.lineThrough)):Text(
- '${categoryItemModel.data.userTags[index].tags[index1].name}',
- style: TextStyle(fontSize: 13),
- ),
- value: inputs[index1],
- onChanged: (bool value) {
- ItemChange(value, index1);
- setState(() {
- _isChecked = value;
- });
- },
- ),
- ),
- ),
- Expanded(
- flex: 0,
- child: Row(
- crossAxisAlignment:
- CrossAxisAlignment.center,
- mainAxisAlignment:
- MainAxisAlignment.spaceEvenly,
- children: [
- Expanded(
- flex: 0,
- child: GestureDetector(
- onTap: (){
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) => ItemListViewScreen(),
- ),
- );
- },
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Text(
- '${categoryItemModel.data.userTags[index].tags[index1].flyerItemsCount}' + " Deals",
- softWrap: true,
- style:
- TextStyle(color: Colors.blue),
- ),
- ),
- )),
- Expanded(
- flex: 0,
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Icon(
- Icons.arrow_forward_ios,
- size: 20,
- color: Colors.blueGrey,
- ),
- )),
- ],
- ),
- )
- ],
- ),
- );
- },
- itemCount: categoryItemModel.data.userTags[index].tags.length, // this is a hardcoded value
- ),
- ],
- ),
- );
- },
- itemCount: categoryItemModel.data.userTags.length, // this is a hardcoded value
- ),
- ],
- ),
- );
- }
- Future<void> PopupCategory(BuildContext context) async {
- await showDialog(
- context: context,
- builder: (BuildContext context) {
- return Dialog(
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(8.0)), //this right here
- child: Container(
- height: 365,
- child: Padding(
- padding: const EdgeInsets.all(12.0),
- child: Column(
- mainAxisSize: MainAxisSize.max,
- children: [
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- Icon(
- Icons.cancel,
- color: Colors.blueGrey,
- size: 20,
- ),
- Text(
- "Recommended",
- style: TextStyle(fontSize: 15),
- )
- ],
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: [
- Icon(
- Icons.check_circle,
- color: Colors.blue,
- size: 20,
- ),
- Text(
- "Done",
- style: TextStyle(fontSize: 14),
- )
- ],
- ),
- ],
- ),
- Divider(
- thickness: 0.8,
- ),
- Container(
- child: GridView.count(
- crossAxisCount: 4,
- childAspectRatio: MediaQuery.of(context).size.width /
- (MediaQuery.of(context).size.height / 1.2),
- crossAxisSpacing: 5.0,
- mainAxisSpacing: 5.0,
- shrinkWrap: true,
- physics: ScrollPhysics(),
- children: List.generate(10, (index) {
- return SingleChildScrollView(
- child: Column(
- children: [
- Expanded(
- flex: 0,
- child: GestureDetector(
- onTap: () {},
- child: Container(
- height: 90,
- child: Column(
- mainAxisAlignment:
- MainAxisAlignment.spaceEvenly,
- crossAxisAlignment:
- CrossAxisAlignment.start,
- children: <Widget>[
- Expanded(
- flex: 0,
- child: CircleAvatar(
- radius: 23,
- backgroundImage: NetworkImage(
- 'https://images.unsplash.com/photo-1523205771623-e0faa4d2813d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=89719a0d55dd05e2deae4120227e6efc&auto=format&fit=crop&w=1953&q=80'),
- ),
- ),
- Expanded(
- flex: 0,
- child: Padding(
- padding:
- const EdgeInsets.all(4.0),
- child: Text(
- "product $index",
- style: TextStyle(
- fontWeight: FontWeight.w400,
- fontSize: 12),
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- ],
- ),
- );
- }),
- ),
- ),
- Expanded(
- flex: 0,
- child: Padding(
- padding: const EdgeInsets.all(2),
- child: Container(
- height: 35,
- width: 300,
- child: TextField(
- decoration: InputDecoration(
- border: OutlineInputBorder(),
- fillColor: Colors.blueGrey[200],
- labelStyle: TextStyle(fontSize: 12),
- contentPadding: EdgeInsets.all(5),
- hintText: 'Search Here',
- prefixIcon: Icon(
- Icons.search,
- color: Colors.blueGrey,
- )),
- ),
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- );
- });
- }
- Future<void> getCategoryLists() async {
- var response = await http.get(
- "${Urls.baseUrl}${Urls.userList}?latitude=${Constants.latitude}&longitude=${Constants.longitude}&radius=100&locale=en",
- headers: {
- "Content-Type": "application/json",
- "Authorization": "Bearer ${userToken}",
- "Accept": "application/json"
- });
- print(response.statusCode);
- print("response shopprefernce " + response.body.toString());
- if (response.statusCode == 200) {
- categoryItemModel = categoryItemModelFromJson(response.body);
- } else {
- final snackBar = SnackBar(content: Text("Cannot connect server,make sure you have internet Connection,Please Try again"));
- _scaffoldKey.currentState.showSnackBar(snackBar);
- }
- }
- }
Add Comment
Please, Sign In to add comment