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

'initState' is inherited as a getter (from 'State') and also a method (from 'AfterLayoutMixin'). #9

Closed
igabice opened this issue Apr 16, 2019 · 2 comments

Comments

@igabice
Copy link

igabice commented Apr 16, 2019

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

class IntroPage extends StatefulWidget {
  @override
  _IntroPageState createState() => _IntroPageState();
}

class _IntroPageState extends State<IntroPage> with AfterLayoutMixin<IntroPage> {
  BuildContext ctx;
  
@override
  Widget build(BuildContext context) {
    ctx = context;
    return new Scaffold(body: new Container(color: Colors.red));
  }

   @override
  void afterFirstLayout(BuildContext context) {
    // Calling the same function "after layout" to resolve the issue.
    firstRun();
  }

  Future<Null> firstRun() async {
     print("first run");
    
  }
}

please healp! I keep getting 'initState' is inherited as a getter (from 'State') and also a method (from 'AfterLayoutMixin').
thats my page code above.

@searzh
Copy link

searzh commented May 15, 2019

If you check the code from AfterLayoutMixin you see that this pub is already overriding your initState method:

mixin AfterLayoutMixin<T extends StatefulWidget> on State<T> {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance
        .addPostFrameCallback((_) => afterFirstLayout(context));
  }

  void afterFirstLayout(BuildContext context);
}

You can't override the same method again. Think of after_layout as a substitute with a slightly different trigger.

@igabice igabice closed this as completed May 28, 2019
@igabice igabice reopened this May 28, 2019
@igabice
Copy link
Author

igabice commented May 28, 2019

thank you. solved!

@igabice igabice closed this as completed May 28, 2019
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