Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:convert';
- import 'package:custom_progress_dialog/custom_progress_dialog.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_svg/svg.dart';
- import 'package:flyerbin_flutter/Utils/Urls.dart';
- import 'package:http/http.dart' as http;
- import 'Model/CategoryItemModel.dart';
- import 'SideDrawerScreen.dart';
- import 'Utils/Constants.dart';
- import 'Utils/CustomDialogs.dart';
- import 'Utils/SharedPrefrence.dart';
- CategoryItemModel categoryItemModelFromJson(String str) => CategoryItemModel.fromJson(json.decode(str));
- String categoryItemModelToJson(CategoryItemModel data) => json.encode(data.toJson());
- 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> category_item_list = [];
- CategoryItemModel categoryItemModel;
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- Future token = SharedPrefrence().getToken();
- token.then((data) async {
- userToken = data;
- 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: 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: 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,
- ),
- ))
- ],
- ),
- ),
- ),
- ),
- 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.data.userTags.length!= 0 ? Container(
- child: 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: 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: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Text(
- "13" + "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
- ),
- ):Center(child: CircularProgressIndicator(),);
- }
- 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 {
- //ProgressDialog dialog = CustomDialogs().showLoadingProgressDialog(context);
- 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("getCategoryLists response " + response.body.toString());
- if (response.statusCode == 200) {
- categoryItemModel = categoryItemModelFromJson(response.body);
- print(categoryItemModel);
- }
- else
- {
- final snackBar = SnackBar(content: Text("Error,Try again"));
- _scaffoldKey.currentState.showSnackBar(snackBar);
- }
- }
- }
- // Future<void> getCategoryLists() async {
- // ProgressDialog dialog = CustomDialogs().showLoadingProgressDialog(context);
- // 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"
- // });
- //
- // Map<String, dynamic> value = json.decode(response.body);
- // if (response.statusCode == 200) {
- // // dialog.dismissProgressDialog(context);
- // try {
- // print("getCategoryLists response " + response.body.toString());
- // Map<String, dynamic> value = json.decode(response.body);
- //
- // var status = value['success'];
- // var message = value['message'];
- // print(status);
- // if (status == true) {
- // try {
- // var rest = value["data"];
- // if (rest.length > 0) {
- // category_item_list = rest.map<CategoryItemModel>((json) => CategoryItemModel.fromJson(json)).toList();
- // print("List Size: ${category_item_list.length}");
- //
- // setState(() {
- // return category_item_list;
- // // print(category_item_list.length);
- // });
- // } else {
- // final snackBar = SnackBar(content: Text("No Data Available"));
- // _scaffoldKey.currentState.showSnackBar(snackBar);
- // }
- // } catch (e) {
- // e.toString();
- // }
- // } else {
- // print("Error...");
- // final snackBar = SnackBar(content: Text(message));
- // _scaffoldKey.currentState.showSnackBar(snackBar);
- // }
- // } catch (e) {
- // print(e.toString());
- // }
- // } else if (response.statusCode == 404) {
- // dialog.dismissProgressDialog(context);
- // var message = value['message'];
- // final snackBar = SnackBar(content: Text(message));
- // _scaffoldKey.currentState.showSnackBar(snackBar);
- // } else if (response.statusCode == 208) {
- // dialog.dismissProgressDialog(context);
- // } else {
- // var message = value['message'];
- // dialog.dismissProgressDialog(context);
- // final snackBar = SnackBar(content: Text(message));
- // _scaffoldKey.currentState.showSnackBar(snackBar);
- // }
- // }
- // }
Add Comment
Please, Sign In to add comment