Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

For loop Expected an identifier.Expected to find ')' error

I am using for loop in my flutter project and I got an error ithat says Expected an identifier.dart(missing_identifier) Expected to find ‘)’.

Error

Error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here’s my code

HomeView File

import 'package:flutter/material.dart';
import 'package:puzzlegame/Widgets/customBox.dart';
import 'dart:io';

class HomeView extends StatefulWidget {
  const HomeView({Key? key}) : super(key: key);

  @override
  _HomeViewState createState() => _HomeViewState();
}

class _HomeViewState extends State<HomeView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Puzzle Game'),
      ),
      body: Center(child: 
      Container(
        child: 
      for (int i=0; i<4; i++){
        for (int j=0; j<4; j++){
          Box(),
        }
        
      },  
        
        ),
      
      ),
      
    );
  }
}

>Solution :

I see a some problems with your code:

  1. Container expect only one child.
  2. Your "for" doesn’t return a widget, and Container is expecting a widget as a child..

I’m not sure what are you trying to do but if you want to have more than one Box you should use a Widget that supports more than one child (like column, listview, row, wrap, etc). Also, don’t use "for" in widget tree.

Also, check the documentation about multichild widgets https://docs.flutter.dev/development/ui/widgets/layout

What are you trying to implement? maybe if you share a screen of the intended UI we could help more.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading