Home > Mobile >  error: The named parameter 'children' isn't defined
error: The named parameter 'children' isn't defined

Time:06-01

i keep on getting this error message

i tried on converting it to child and then it keeps on getting an error. heres my code:

// TODO: Build a grid of cards (102) children: [ Card( clipBehavior: Clip.antiAlias, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ AspectRatio( aspectRatio: 18.0 / 11.0, child: Image.asset('assets/diamond.png'), ), Padding( padding: const EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 8.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('Title'), const SizedBox(height: 8.0), Text('Secondary Text'), ], ), ), ], ), ), ],

CodePudding user response:

You are getting error because the ')' is typed before children. Also, You can't use children parameter 2 times.

CodePudding user response:

You can use variable List<Widget> for Item of GridView

Example:

'package:flutter/material.dart';

class HomeScreen extends StatelessWidget {
  HomeScreen({Key? key}) : super(key: key);

  List<Widget> listWidget = [
    Card(
      clipBehavior: Clip.antiAlias,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          AspectRatio(
            aspectRatio: 18.0 / 11.0,
            child: Image.asset('assets/diamond.png'),
          ),
          Padding(
            padding: const EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 8.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text('Title'),
                const SizedBox(height: 8.0),
                Text('Secondary Text'),
              ],
            ),
          ),
        ],
      ),
    ),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: GridView.count(
        crossAxisCount: 2,
        childAspectRatio: 8 / 9,
        children: listWidget,
      ),
    );
  }
}
  • Related