Skip to content

Contradictory Suggestions by Dart Analysis Tool #4895

@rukiddy70

Description

@rukiddy70

Type: Bug

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

bool _isButtonASelected = false;
bool _isButtonBSelected = false;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'my_app',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State createState() => _MyHomePageState();
}

class _MyHomePageState extends State {
  DateTime? _selectedDate;

  Future _selectDate() async {
    final DateTime? pickedDate = await showDatePicker(
      context: context,
      initialDate: DateTime.now(),
      firstDate: DateTime(1900),
      lastDate: DateTime(2100),
    );
    if (pickedDate != null && pickedDate != _selectedDate) {
      setState(() {
        _selectedDate = pickedDate;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Date Picker Form'),
      ),
      body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
// Add your form fields and other widgets here
              Text('Select Date:',
                  style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
              _selectedDate != null
                  ? Text('${DateFormat('dd/MM/yyyy').format(_selectedDate!)}')
                  : Text('No date selected'),
              SizedBox(width: 16),
              ElevatedButton(
                onPressed: _selectDate,
                child: Text('Pick Date'),
              ),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text('Shift Number',
                  style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
              SizedBox(width: 16),
              ElevatedButton(
                child: Text('A'),
                onPressed: () {
                  setState(() {
                    _isButtonASelected = true;
                    _isButtonBSelected = false;
                  });
                },
                style: ElevatedButton.styleFrom(
                  backgroundColor:
                      _isButtonASelected ? Colors.blue : Colors.grey,
                ),
              ),
              SizedBox(width: 16),
              ElevatedButton(
                child: Text('B'),
                onPressed: () {
                  setState(() {
                    _isButtonASelected = false;
                    _isButtonBSelected = true;
                  });
                },
                style: ElevatedButton.styleFrom(
                    backgroundColor:
                        _isButtonBSelected ? Colors.blue : Colors.grey),
              ),
            ],
          )),
    );
  }
}

Error reported by Dart Analysis Tool:

"Positional arguments must occur before named arguments.
Try moving all of the positional arguments before the named arguments." Ln 64, Col 9
Suggestion by DAT: convert to a named argument by wrapping Row () under child ().
Error: it then shows another error :
The argument for the named parameter 'child' was already specified.
Try removing one of the named arguments, or correcting one of the names to reference a different named parameter. Ln 64, Col 9
"Too many positional arguments: 0 expected, but 1 found.
Try removing the extra positional arguments, or specifying the name for named arguments." Ln 64, Col 9
Suggestions by DAT: convert to named argument.
After implementing it, the tool shows the below error:
"The argument for the named parameter 'child' was already specified.
Try removing one of the named arguments, or correcting one of the names to reference a different named parameter."
Ln 64, Col 9
VS Code version: Code 1.85.0 (microsoft/vscode@af28b32, 2023-12-06T20:48:09.019Z)
OS version: Windows_NT x64 10.0.19045
Modes:

System Info
Extensions (22)
A/B Experiments

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions