I tried to run my first Flutter app but received this error:
No named parameter with the name 'textDirection' ...`
After trying unsuccessful web + AI suggestions I decided to run the sample app that creates automatically in new flutter projects (VS Code) but the error remain the same.
The code
The default flutter app with small change – due to the error I added the Directionality widget
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.deepPurple,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Directionality(
textDirection: TextDirection.ltr,
child: Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline6,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
),
);
}
}
The error:
Launching libmain.dart on sdk gphone64 x86 64 in debug mode...
/C:/flutter/packages/flutter/lib/src/widgets/debug.dart:354:57: Error: No named parameter with the name 'textDirection'.
ErrorSummary('No Directionality widget found.', textDirection: TextDirection.ltr,),
^^^^^^^^^^^^^
/C:/flutter/packages/flutter/lib/src/foundation/assertions.dart:310:3: Context: Found this candidate, but the arguments don't match.
ErrorSummary(super.message) : super(level: DiagnosticLevel.summary);
^^^^^^^^^^^^
Target kernel_snapshot failed: Exception
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:flutterbinflutter.bat'' finished with non-zero exit value 1
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 6s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
Here is the flutter doctor (flutter 3.16.9):
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.16.9, on Microsoft Windows [Version 10.0.22631.3007],
locale en-IL)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.6)
[√] Android Studio (version 2023.1)
[√] VS Code, 64-bit edition (version 1.73.0)
[√] Connected device (4 available)
[√] Network resources
What is wrong here?
Thanks!
2
Answers
Here is the pubspec.yaml file:
Just remove this part
textDirection: TextDirection.ltr
from your build method of _MyHomePageState class, so your build method will look like this.