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

warning when define member in widget #36899

Closed
zzc-tongji opened this issue Jul 25, 2019 · 2 comments
Closed

warning when define member in widget #36899

zzc-tongji opened this issue Jul 25, 2019 · 2 comments

Comments

@zzc-tongji
Copy link

Here is my code.

import 'package:flutter/material.dart';

class Home extends StatelessWidget {
  Map _parameters;

  Home([Map params]) {
    _parameters = params;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Home'),
      ),
      body: Center(
        child: Column(
          children: [
            Text(_parameters.toString()),
          ],
        ),
      ),
    );
  }
}

IDE says that there is a warning.

info: This class (or a class which this class inherits from) is marked as '@immutable', but one or more of its instance fields are not final: Home._parameters (must_be_immutable at [hello_flutter_boost] lib/page/home.dart:6)

Here is a problem. I have to define _parameters to store parameter from Home() (constructor) so the widget can get parameters from outside. But it causes a warning.

Is there any way to avoid the warning?

@zzc-tongji
Copy link
Author

zzc-tongji commented Jul 25, 2019

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant