fluttermaterial-uiflutter-layoutnamed-parametersflutter-card

Flutter named paramter is not defined for Card widget


I'm trying to create a reusable Card widget to use in other dart files throughout my app. I keep getting a named parameter is not defined error. What could the problem be here? Things I've already tried:

card.dart

Errors on line 14, 15 and 16

home.dart

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

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Card'),
        ),
        body: Card());
  }
}

Description of error

enter image description here


Solution

  • Please change the class name differ from Card. Beacuse you already have Card class in dart pakage.

    Solution:

    class MyCard extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            body: Card(color: Colors.red,));
      }
    }