मेरे पास कोड का सबसे सरल सेट है जो स्पंदन पर काम नहीं कर रहा है। यह लूप के लिए एक आसान है, जो अपवाद दे रहा है।

List vendorMainCategory = ['one', 'two', 'three', 'four']
List testList = [];
List testList1 = [];

testFunction () {

testList1 = vendorMainCategory
print(testList1)

for(int i =0; i<4; i++){

testList[i] = testList1[i]

   }
}

जैसा कि कंसोल में देखा जा सकता है, फ़ंक्शन 'प्रिंट (testList1)' लाइन तक चलता है, और जैसे ही लूप शुरू होता है, एक त्रुटि का सामना करता है। ऐसा क्यों हो सकता है समझ में नहीं आ रहा है। किसी भी तरह की सहायता की हम सराहना करेंगे।

फ़्लैटबटन की ऑनप्रेस्ड प्रॉपर्टी का उपयोग करके इस फ़ंक्शन को कॉल करने पर, मुझे इसे कंसोल में दिखाया गया है:

I/flutter ( 5687): [one, two, three, four]
E/flutter ( 5687): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] 
Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 0
E/flutter ( 5687): #0      List._setIndexed (dart:core-patch/growable_array.dart:152:72)
E/flutter ( 5687): #1      List.[]= (dart:core-patch/growable_array.dart:149:5)
E/flutter ( 5687): #2      _TestPage1State.newFunction (package:fetchapp/pages/test_page1.dart:80:16)
E/flutter ( 5687): #3      _TestPage1State.build.<anonymous closure> (package:fetchapp/pages/test_page1.dart:109:29)
E/flutter ( 5687): #4      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:779:14)
E/flutter ( 5687): #5      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:862:36)
E/flutter ( 5687): #6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 5687): #7      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
E/flutter ( 5687): #8      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
E/flutter ( 5687): #9      BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:199:7)
E/flutter ( 5687): #10     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:470:9)
E/flutter ( 5687): #11     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
E/flutter ( 5687): #12     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:117:9)
E/flutter ( 5687): #13     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
E/flutter ( 5687): #14     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:115:18)
E/flutter ( 5687): #15     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:7)
E/flutter ( 5687): #16     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter ( 5687): #17     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter ( 5687): #18     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 5687): #19     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 5687): #20     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 5687): #21     _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter ( 5687): #22     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter ( 5687): #23     _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter ( 5687): #24     _invoke1 (dart:ui/hooks.dart:275:10)
E/flutter ( 5687): #25     _dispatchPointerDataPacket (dart:ui/hooks.dart:184:5)
E/flutter ( 5687): W/IInputConnectionWrapper( 5687): getExtractedText on inactive InputConnection
W/IInputConnectionWrapper( 5687): getTextBeforeCursor on inactive InputConnection
D/Surface ( 5687): Surface::disconnect(this=0x7e08d6d000,api=1)
D/Surface ( 5687): Surface::disconnect(this=0x7e08d6d000,api=-1)
D/Surface ( 5687): Surface::disconnect(this=0x7e15bfa000,api=1)
V/PhoneWindow( 5687): DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@9a76da, this = DecorView@897370b[MainActivity]
0
Chirag Rajgariah 8 अप्रैल 2020, 22:15

1 उत्तर

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

add का उपयोग करने का प्रयास कैसे करें?

List vendorMainCategory = ['one', 'two', 'three', 'four'];
List testList = [];
List testList1 = [];

testFunction () {

testList1 = vendorMainCategory;
print(testList1);

for(int i =0; i<4; i++){

testList.add(testList1[i]); //<--changed to add

   }
}
  testFunction();
print(testList); //[one, two, three, four]
1
LonelyWolf 8 अप्रैल 2020, 19:25