वर्तमान में एक त्रुटि को डीबग करने का प्रयास किया जा रहा है जो तब होती है जब आइटम को कार्ट में जोड़ा जाता है और उस कार्ट में नेविगेट किया जाता है जहां कार्ट आइटम प्रदर्शित किए जाने चाहिए।

कार्ट में आइटम जोड़ने की कार्यक्षमता संचालित होती है। आइटम कार्ट में जोड़े जाने पर ही त्रुटि हुई। बिल्ड क्रैश नहीं होता है।

त्रुटि कार्ट आइटम विजेट के भीतर है। Cart_item.dart को Cart_screen.dart में नेस्ट किया गया है।

-------------------------------------अपडेट करें------------ ------------------------

ListTile के भीतर leading: के रूप में पहचाने जाने पर मैं विशेष रूप से सर्कल अवतार विजेट से बंधे होने के रूप में इस त्रुटि का निदान करने में सक्षम हूं। जब अन्य विजेट्स (अर्थात टेक्स्ट) की पहचान leading: के रूप में की जाती है, तो कोई त्रुटि नहीं होती है। लिस्टटाइल में सर्कल अवतार को leading: के रूप में क्यों नहीं पहचाना जा सकता है?

त्रुटि:


[38;5;248m════════ Exception caught by rendering library ═════════════════════════════════[39;49m
[38;5;244mThe following assertion was thrown during performLayout():[39;49m
Leading widget consumes entire tile width. Please use a sized widget, or consider replacing ListTile with a custom widget (see https://api.flutter.dev/flutter/material/ListTile-class.html#material.ListTile.4)
'package:flutter/src/material/list_tile.dart':
Failed assertion: line 1547 pos 7: 'tileWidth != leadingSize.width'


[38;5;248mEither the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=BUG.md
[39;49m

[38;5;244mThe relevant error-causing widget was[39;49m
[38;5;248mListTile[39;49m
 lib\widgets\cart_item.dart
[38;5;244mWhen the exception was thrown, this was the stack[39;49m
[38;5;244m#2      _RenderListTile.performLayout[39;49m
 package:flutter/…/material/list_tile.dart
[38;5;244m#3      RenderObject.layout[39;49m
 package:flutter/…/rendering/object.dart
[38;5;244m#4      RenderPadding.performLayout[39;49m
 package:flutter/…/rendering/shifted_box.dart
[38;5;244m#5      RenderObject.layout[39;49m
 package:flutter/…/rendering/object.dart
[38;5;244m#6      RenderProxyBoxMixin.performLayout[39;49m
 package:flutter/…/rendering/proxy_box.dart
[38;5;244m...[39;49m
[38;5;244mThe following RenderObject was being processed when the exception was fired: _RenderListTile#414b8 relayoutBoundary=up38 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE[39;49m
[38;5;244mRenderObject: _RenderListTile#414b8 relayoutBoundary=up38 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE[39;49m
    [38;5;244mparentData: offset=Offset(0.0, 0.0) (can use size)[39;49m
    [38;5;244mconstraints: BoxConstraints(w=11.2, 0.0<=h<=Infinity)[39;49m
    [38;5;244msize: MISSING[39;49m
    [38;5;244mleading: RenderConstrainedBox#0efc0 relayoutBoundary=up39 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE[39;49m
        [38;5;244mparentData: offset=Offset(0.0, 0.0) (can use size)[39;49m
        [38;5;244mconstraints: BoxConstraints(0.0<=w<=11.2, 0.0<=h<=56.0)[39;49m
        [38;5;244msize: Size(11.2, 40.0)[39;49m
        [38;5;244madditionalConstraints: BoxConstraints(w=40.0, h=40.0)[39;49m
        [38;5;244mchild: RenderDecoratedBox#c9777 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE[39;49m
            [38;5;244mparentData: <none> (can use size)[39;49m
            [38;5;244mconstraints: BoxConstraints(w=11.2, h=40.0)[39;49m
            [38;5;244msize: Size(11.2, 40.0)[39;49m
            [38;5;244mdecoration: BoxDecoration[39;49m
                [38;5;244mcolor: Color(0xff1976d2)[39;49m
                [38;5;244mshape: circle[39;49m
            [38;5;244mconfiguration: ImageConfiguration(bundle: PlatformAssetBundle#ed2ae(), devicePixelRatio: 3.5, locale: en_US, textDirection: TextDirection.ltr, platform: android)[39;49m
            [38;5;244mchild: RenderPositionedBox#1179f NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE[39;49m
                [38;5;244mparentData: <none> (can use size)[39;49m
                [38;5;244mconstraints: BoxConstraints(w=11.2, h=40.0)[39;49m
                [38;5;244msize: Size(11.2, 40.0)[39;49m
                [38;5;244malignment: center[39;49m
                [38;5;244mtextDirection: ltr[39;49m
                [38;5;244mwidthFactor: expand[39;49m
                [38;5;244mheightFactor: expand[39;49m
                [38;5;244mchild: RenderParagraph#1a8e3 relayoutBoundary=up1 NEEDS-PAINT[39;49m
                    [38;5;244mparentData: offset=Offset(0.1, 0.0) (can use size)[39;49m
                    [38;5;244mconstraints: BoxConstraints(0.0<=w<=11.2, 0.0<=h<=40.0)[39;49m
                    [38;5;244msize: Size(11.0, 40.0)[39;49m
                    [38;5;244mtextAlign: start[39;49m
                    [38;5;244mtextDirection: ltr[39;49m
                    [38;5;244msoftWrap: wrapping at box width[39;49m
                    [38;5;244moverflow: clip[39;49m
                    [38;5;244mlocale: en_US[39;49m
                    [38;5;244mmaxLines: unlimited[39;49m
    [38;5;244mtitle: RenderParagraph#8f830 NEEDS-LAYOUT NEEDS-PAINT[39;49m
        [38;5;244mparentData: offset=Offset(0.0, 0.0)[39;49m
        [38;5;244mconstraints: MISSING[39;49m
        [38;5;244msize: MISSING[39;49m
        [38;5;244mtextAlign: start[39;49m
        [38;5;244mtextDirection: ltr[39;49m
        [38;5;244msoftWrap: wrapping at box width[39;49m
        [38;5;244moverflow: clip[39;49m
        [38;5;244mlocale: en_US[39;49m
        [38;5;244mmaxLines: unlimited[39;49m
        [38;5;244mtext: TextSpan[39;49m
            [38;5;244mdebugLabel: ((englishLike subhead 2014).merge((blackMountainView subtitle1).apply)).copyWith[39;49m
            [38;5;244minherit: false[39;49m
            [38;5;244mcolor: Color(0xdd000000)[39;49m
            [38;5;244mfamily: Lato[39;49m
            [38;5;244msize: 16.0[39;49m
            [38;5;244mweight: 400[39;49m
            [38;5;244mbaseline: alphabetic[39;49m
            [38;5;244mdecoration: TextDecoration.none[39;49m
            [38;5;244m"Yellow Scarf"[39;49m
    [38;5;244msubtitle: RenderParagraph#efae3 NEEDS-LAYOUT NEEDS-PAINT[39;49m
        [38;5;244mparentData: offset=Offset(0.0, 0.0)[39;49m
        [38;5;244mconstraints: MISSING[39;49m
        [38;5;244msize: MISSING[39;49m
        [38;5;244mtextAlign: start[39;49m
        [38;5;244mtextDirection: ltr[39;49m
        [38;5;244msoftWrap: wrapping at box width[39;49m
        [38;5;244moverflow: clip[39;49m
        [38;5;244mlocale: en_US[39;49m
        [38;5;244mmaxLines: unlimited[39;49m
        [38;5;244mtext: TextSpan[39;49m
            [38;5;244mdebugLabel: ((englishLike body1 2014).merge((blackMountainView bodyText2).apply)).copyWith[39;49m
            [38;5;244minherit: false[39;49m
            [38;5;244mcolor: Color(0x8a000000)[39;49m
            [38;5;244mfamily: Lato[39;49m
            [38;5;244msize: 14.0[39;49m
            [38;5;244mweight: 400[39;49m
            [38;5;244mbaseline: alphabetic[39;49m
            [38;5;244mdecoration: TextDecoration.none[39;49m
            [38;5;244m"x 1"[39;49m
    [38;5;244mtrailing: RenderParagraph#53ad3 relayoutBoundary=up39 NEEDS-PAINT[39;49m
        [38;5;244mparentData: offset=Offset(0.0, 0.0) (can use size)[39;49m
        [38;5;244mconstraints: BoxConstraints(0.0<=w<=11.2, 0.0<=h<=56.0)[39;49m
        [38;5;244msize: Size(11.0, 56.0)[39;49m
        [38;5;244mtextAlign: start[39;49m
        [38;5;244mtextDirection: ltr[39;49m
        [38;5;244msoftWrap: wrapping at box width[39;49m
        [38;5;244moverflow: clip[39;49m
        [38;5;244mlocale: en_US[39;49m
        [38;5;244mmaxLines: unlimited[39;49m
        [38;5;244mtext: TextSpan[39;49m
            [38;5;244mdebugLabel: (englishLike body1 2014).merge((blackMountainView bodyText2).apply)[39;49m
            [38;5;244minherit: false[39;49m
            [38;5;244mcolor: Color(0xdd000000)[39;49m
            [38;5;244mfamily: Lato[39;49m
            [38;5;244msize: 14.0[39;49m
            [38;5;244mweight: 400[39;49m
            [38;5;244mbaseline: alphabetic[39;49m
            [38;5;244mdecoration: TextDecoration.none[39;49m
            [38;5;244m"$19.99"[39;49m
[38;5;248m════════════════════════════════════════════════════════════════════════════════[39;49m

[38;5;248m════════ Exception caught by rendering library ═════════════════════════════════[39;49m
RenderBox was not laid out: _RenderListTile#414b8 relayoutBoundary=up38 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1785 pos 12: 'hasSize'

[38;5;244mThe relevant error-causing widget was[39;49m
[38;5;248mListTile[39;49m
 lib\widgets\cart_item.dart
[38;5;248m════════════════════════════════════════════════════════════════════════════════[39;49m

...

शेष विजेट ट्री की संपूर्णता में त्रुटियों को फेंकना जारी रखता है।

त्रुटि की जड़ यहां होती है -cart_item.dart: (प्रदाता पैकेज पर ध्यान न दें)

import 'package:flutter/material.dart';
// import 'package:provider/provider.dart';

// import '../models/product_model.dart';
// import 'product_item.dart';

class CartItem extends StatelessWidget {
  CartItem({this.id, this.price, this.quantity, this.title});
  final String id;
  final double price;
  final int quantity;
  final String title;

  @override
  Widget build(BuildContext context) {
    // final product = Provider.of<Product>(context, listen: false);
    return Card(
      margin: EdgeInsets.symmetric(
        vertical: 15,
        horizontal: 4,
      ),
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: ListTile(
          leading: CircleAvatar(
            child: Text('\$$price'),
          ),
          //Image.network(product.imageURL),
          title: Text(title),
          subtitle: Text('x $quantity'),
          trailing: Text('\$$price'),
        ),
      ),
    );
  }
}

संदर्भ के लिए - कार्ट_स्क्रीन.डार्ट:

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../models/cart.dart' show Cart;

import '../widgets/cart_item.dart';

class CartScreen extends StatelessWidget {
  static const routeName = '/cart';
  @override
  Widget build(BuildContext context) {
    final cart = Provider.of<Cart>(context);
    return Scaffold(
      appBar: AppBar(
        title: Text('Your Cart'),
      ),
      body: Column(
        // mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
          Card(
            margin: EdgeInsets.all(15.0),
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text('Total',
                      style: TextStyle(
                        fontSize: 20,
                      )),
                  Spacer(),
                  Chip(
                    label: Text('\$${cart.totalAmount}'),
                  ),
                  FlatButton(
                    child: Text('order now'.toUpperCase()),
                    textColor: Theme.of(context).primaryColor,
                    onPressed: () {},
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  Expanded(
                    child: ListView.builder(
                      shrinkWrap: true,
                      itemCount: cart.items.length,
                      itemBuilder: (ctx, index) => CartItem(
                          id: cart.items.values.toList()[index].id,
                          price: cart.items.values.toList()[index].price,
                          quantity: cart.items.values.toList()[index].quantity,
                          title: cart.items.values.toList()[index].title),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
0
Matt 5 फरवरी 2021, 06:11

2 जवाब

सबसे बढ़िया उत्तर

यह कार्ट_आइटम में लिस्टटाइल के भीतर अग्रणी पैरामीटर से बंधा नहीं था, जिसे त्रुटि ने मुझे निर्देशित किया था।

यह कार्ट_स्क्रीन के भीतर एक प्रतिपादन मुद्दा था। ListView.builder को कार्ड विजेट के बाहर होने की आवश्यकता है। यहां बताया गया है कि मैंने कोड कैसे तय किया:

Cart_item में कोड में कोई बदलाव नहीं किया गया था।

कार्ट_स्क्रीन में अपडेट किया गया कोड:

class CartScreen extends StatelessWidget {
  static const routeName = '/cart';
  @override
  Widget build(BuildContext context) {
    final cart = Provider.of<Cart>(context);
    return Scaffold(
      appBar: AppBar(
        title: Text('Your Cart'),
      ),
      body: Column(
        // mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
          Card(
            margin: EdgeInsets.all(15.0),
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text('Total',
                      style: TextStyle(
                        fontSize: 20,
                      )),
                  Spacer(),
                  Chip(
                    label: Text('\$${cart.totalAmount}'),
                  ),
                  FlatButton(
                    child: Text('order now'.toUpperCase()),
                    textColor: Theme.of(context).primaryColor,
                    onPressed: () {},
                  ),
                ],
              ),
            ),
          ),
          SizedBox(
            height: 10,
          ),
          Expanded(
            child: ListView.builder(
              shrinkWrap: true,
              itemCount: cart.items.length,
              itemBuilder: (ctx, index) => CartItem(
                  id: cart.items.values.toList()[index].id,
                  price: cart.items.values.toList()[index].price,
                  quantity: cart.items.values.toList()[index].quantity,
                  title: cart.items.values.toList()[index].title),
            ),
          ),
        ],
      ),
    );
  }
}
1
Matt 6 फरवरी 2021, 18:59
class CartItem extends StatelessWidget {
  CartItem({this.id, this.price, this.quantity, this.title});
  final String id;
  final double price;
  final int quantity;
  final String title;

  @override
  Widget build(BuildContext context) {
    // final product = Provider.of<Product>(context, listen: false);
    return Card(
      margin: EdgeInsets.symmetric(
        vertical: 15,
        horizontal: 4,
      ),
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: ListTile(
          leading: CircleAvatar(
            child: Text('\$$price'),
          ),
          //Image.network(product.imageURL),
          title: Text(title),
          subtitle: Text('x $quantity'),
          trailing: Text('\$$price'),
        ),
      ),
    );
  }
}

class CartScreen extends StatelessWidget {
  static const routeName = '/cart';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Your Cart'),
      ),
      body: Column(
        // mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
          Card(
            margin: EdgeInsets.all(15.0),
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text('Total',
                      style: TextStyle(
                        fontSize: 20,
                      )),
                  Spacer(),
                  Chip(
                    label: Text('\$${50}'),
                  ),
                  FlatButton(
                    child: Text('order now'.toUpperCase()),
                    textColor: Theme.of(context).primaryColor,
                    onPressed: () {},
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  Expanded(
                    child: ListView.builder(
                      shrinkWrap: true,
                      itemCount: 3,
                      itemBuilder: (ctx, index) => CartItem(
                          id: index.toString(),
                          price: index.toDouble(),
                          quantity: index,
                          title: index.toString()),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}

मुझे आपके कोड से कोई समस्या नहीं मिली, कृपया इसमें एक बार जांच लें

0
Balasubramani Sundaram 5 फरवरी 2021, 06:28