Skip to content
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

Attempted to use type '_SwiperState' as a function. #5

Closed
shockw4ver opened this issue Jul 18, 2018 · 1 comment
Closed

Attempted to use type '_SwiperState' as a function. #5

shockw4ver opened this issue Jul 18, 2018 · 1 comment

Comments

@shockw4ver
Copy link

This is the part of my code that use swiper.

@override
  Widget build (BuildContext context) {
    return new Center(
      child: new Container(
        child: new Container(
          height: 280.0,
          child: new Swiper(
            itemBuilder: (BuildContext context,int index){
              return new Image.network("http://via.placeholder.com/350x150",fit: BoxFit.fill,);
            },
            itemCount: 3,
            pagination: new SwiperPagination(),
            control: new SwiperControl(),
          ),
        ),
      )
    );
  }

And cause exception:

I/flutter ( 4576): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 4576): The following NoSuchMethodError was thrown building Container(constraints:
I/flutter ( 4576): BoxConstraints(0.0<=w<=Infinity, h=280.0)):
I/flutter ( 4576): Attempted to use type '_SwiperState' as a function. Since types do not define a method 'call', this
I/flutter ( 4576): is not possible. Did you intend to call the _SwiperState constructor and forget the 'new' operator?
I/flutter ( 4576): Receiver: _SwiperState
I/flutter ( 4576): Tried calling: _SwiperState()
I/flutter ( 4576): 
I/flutter ( 4576): When the exception was thrown, this was the stack:
I/flutter ( 4576): #0      Object.noSuchMethod (dart:core-patch/dart:core/object_patch.dart:46)
I/flutter ( 4576): #1      Swiper.createState (package:flutter_swiper/src/swiper.dart:260:24)
I/flutter ( 4576): #2      new StatefulElement (package:flutter/src/widgets/framework.dart:3693:23)
I/flutter ( 4576): #3      StatefulWidget.createElement (package:flutter/src/widgets/framework.dart:781:42)
I/flutter ( 4576): #4      Element.inflateWidget (package:flutter/src/widgets/framework.dart:2888:40)
...

What happend...

@jzoom
Copy link
Member

jzoom commented Jul 18, 2018

Make sure to use the latest sdk version. The keyword "new" would be optional in most of the cases.
You can find that here : dart-lang/sdk#30921 , and here : https://github.com/dart-lang/sdk/blob/master/docs/language/informal/optional-new-const.md.
I'll fix this issue by using "new" .

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

2 participants