Skip to content

Error in file pages/products_list_page.dart #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jonahfang opened this issue Aug 19, 2018 · 3 comments
Open

Error in file pages/products_list_page.dart #8

jonahfang opened this issue Aug 19, 2018 · 3 comments

Comments

@jonahfang
Copy link

class ProductsListPageBody extends StatelessWidget {
  BuildContext context;  
  ProductScopedModel model;

  int pageIndex = 1;  <----- must final!
@jonahfang
Copy link
Author

I changed the products_list_page.dart as follows and it seems work:

import 'package:flutter/material.dart';

import 'package:scoped_model/scoped_model.dart';

import '../scoped_model/product_scoped_model.dart';
import '../widgets/products_list_item.dart';

class ProductsListPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    ProductScopedModel productModel = ProductScopedModel();
    productModel.parseProductsFromResponse(95, 1);

    return ScopedModel<ProductScopedModel>(
      model: productModel,
      child: Scaffold(
        appBar: AppBar(
          centerTitle: true,
          backgroundColor: Colors.white,
          title: Text(
            "PRODUCT LIST",
            style: TextStyle(
              color: Colors.black,
            ),
          ),
        ),
        body: ProductsListPageBody(),
      ),
    );
  }
}

class PageIndexWrapper {
  int _pageIndex = 1;
  int get value => _pageIndex;
  void increment() {
    _pageIndex++;
  }
}

class ProductsListPageBody extends StatelessWidget {
  final pageIndex = PageIndexWrapper();

  @override
  Widget build(BuildContext context) {
    return ScopedModelDescendant<ProductScopedModel>(
      builder: (context, child, model) {
        return model.isLoading
            ? _buildCircularProgressIndicator()
            : _buildListView(model, context);
      },
    );
  }

  _buildCircularProgressIndicator() {
    return Center(
      child: CircularProgressIndicator(),
    );
  }

  _buildListView(model, context) {
    Size screenSize = MediaQuery.of(context).size;

    return Padding(
      padding: const EdgeInsets.only(bottom: 8.0),
      child: model.getProductsCount() == 0
          ? Center(child: Text("No products available."))
          : ListView.builder(
              itemCount: model.getProductsCount() + 2,
              itemBuilder: (context, index) {
                if (index == model.getProductsCount()) {
                  if (model.hasMoreProducts) {
                    pageIndex.increment();
                    model.parseProductsFromResponse(95, pageIndex.value);
                    return Padding(
                      padding: const EdgeInsets.only(top: 16.0),
                      child: Center(child: CircularProgressIndicator()),
                    );
                  }
                  return Container();
                } else if (index == 0) {
                  //0th index would contain filter icons
                  return _buildFilterWidgets(screenSize);
                } else if (index % 2 == 0) {
                  //2nd, 4th, 6th.. index would contain nothing since this would
                  //be handled by the odd indexes where the row contains 2 items
                  return Container();
                } else {
                  //1st, 3rd, 5th.. index would contain a row containing 2 products

                  if (index > model.getProductsCount() - 1) {
                    return Container();
                  }

                  return ProductsListItem(
                    product1: model.productsList[index - 1],
                    product2: model.productsList[index],
                  );
                }
              },
            ),
    );
  }

  _buildFilterWidgets(Size screenSize) {
    return Container(
      margin: const EdgeInsets.all(12.0),
      width: screenSize.width,
      child: Card(
        elevation: 4.0,
        child: Container(
          padding: const EdgeInsets.symmetric(vertical: 12.0),
          child: Row(
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[
              _buildFilterButton("SORT"),
              Container(
                color: Colors.black,
                width: 2.0,
                height: 24.0,
              ),
              _buildFilterButton("REFINE"),
            ],
          ),
        ),
      ),
    );
  }

  _buildFilterButton(String title) {
    return InkWell(
      onTap: () {
        print(title);
      },
      child: Row(
        children: <Widget>[
          Icon(
            Icons.arrow_drop_down,
            color: Colors.black,
          ),
          SizedBox(
            width: 2.0,
          ),
          Text(title),
        ],
      ),
    );
  }
}

@jegathispandian
Copy link

I am getting following exception

Running "flutter packages get" in flutter-products-tutorial-master... 0.8s
Your application could not be compiled, because its dependencies could not be established.
The following Dart file:
/Users/jegathispandian/icicle/work/Workspace/flutter-products-tutorial-master/lib/scoped_model/product_scoped_model.dart
...refers, in an import, to the following library:
/Users/jegathispandian/icicle/work/Workspace/flutter-products-tutorial-master/lib/util/remote_config.dart
Unfortunately, that library does not appear to exist on your file system.

@goltvn
Copy link

goltvn commented Jul 8, 2019

@jegathispandian same thing here, doesnt seem like this been compiled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants