getting two major errors
139
Flutter changed the names for theme a while ago, fix the first error using this for example, or use titleMedium/titleBig
.
TextStyle textStyle=Theme.of(context).textTheme.titleSmall
Fix the 2. error by adding a default value to your last function. Null-Safety forces you to return something non-null from your function, so either make the function nullable, or change the bahaviour to this:
getPriorityAsString(int value) {
String priority = "";
switch (value) {
case 1:
priority = "";
break;
case 2:
priority = "";
break;
}
return priority;
}
Author by
vinay
Updated on January 03, 2023Comments
-
vinay over 1 year
While creating to-do app I got stuck in the middle of the execution of project
import 'package:flutter/material.dart'; import '../database_helper.dart'; import '../note.dart'; import 'package:intl/intl.dart'; class NoteDetail extends StatefulWidget { final String appBarTitle; final Note note; NoteDetail(this.note, this.appBarTitle); @override State<StatefulWidget> createstate(){ return NoteDetailState(this.note,this.appBarTitle); } State<StatefulWidget> createState() { throw UnimplementedError(); } } class NoteDetailState extends State<NoteDetail>{ static var _Priorities=['HIGH','LOW']; DatabaseHelper helper=DatabaseHelper(); String appBarTitle; Note note; NoteDetailState(this.note,this.appBarTitle); TextEditingController titleController =TextEditingController(); TextEditingController descriptionController=TextEditingController(); @override Widget build(BuildContext context) { TextStyle textStyle=Theme.of(context).textTheme.****title****;-this is the error i am getting titleController.text=note.title; descriptionController=note.description as TextEditingController; return WillPopScope( onWillPop: ()**{** - here is the another error moveToLastScreen();}, child: Scaffold( appBar: AppBar( title: Text(appBarTitle), leading: IconButton( icon:Icon(Icons.arrow_back), onPressed: (){ moveToLastScreen(); }, ), ), body: Padding( padding: EdgeInsets.all(10.0), child: Card( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(15.0), ), child: ListView( children: <Widget>[ Padding( padding: EdgeInsets.only(top: 15.0, bottom: 5.0), //dropdown menu child: new ListTile( leading: const Icon(Icons.low_priority), title: DropdownButton( items: _Priorities.map((String dropDownStringItem) { return DropdownMenuItem<String>( value: dropDownStringItem, child: Text(dropDownStringItem, style: TextStyle( fontSize: 20.0, fontWeight: FontWeight.bold, color: Colors.red)), ); }).toList(), value: getPriorityAsString(note.priority), onChanged: (valueSelectedByUser) { setState(() { updatePriorityAsInt(valueSelectedByUser); }); }), ), ), // Second Element Padding( padding: EdgeInsets.only(top: 15.0, bottom: 15.0, left: 15.0), child: TextField( controller: titleController, style: textStyle, onChanged: (value) { updateTile(); }, decoration: InputDecoration( labelText: 'Title', labelStyle: textStyle, icon: Icon(Icons.title), ), ), ), // Third Element Padding( padding: EdgeInsets.only(top: 15.0, bottom: 15.0, left: 15.0), child: TextField( controller: descriptionController, style: textStyle, onChanged: (value) { updatedescription(); }, decoration: InputDecoration( labelText: 'Details', icon: Icon(Icons.details), ), ), ), // Fourth Element Padding( padding: EdgeInsets.all(15.0), child: Row( children: <Widget>[ Expanded( child: RaisedButton( textColor: Colors.white, color: Colors.green, padding: const EdgeInsets.all(8.0), child: Text( 'Save', textScaleFactor: 1.5, ), onPressed: () { setState(() { debugPrint("Save button clicked"); _save(); }); }, ), ), Container( width: 5.0, ), Expanded( child: RaisedButton( textColor: Colors.white, color: Colors.red, padding: const EdgeInsets.all(8.0), child: Text( 'Delete', textScaleFactor: 1.5, ), onPressed: () { setState(() { _delete(); }); }, ), ), ], ), ), ], ), ), ), ), ); } void updateTile(){ note.title=titleController.text; } void updatedescription(){ note.description=descriptionController.text; } void moveToLastScreen(){ Navigator.pop(context,true); } void _save() async{ moveToLastScreen(); note.date=DateFormat.yMMMd().format(DateTime.now()); int result; if (note.id !=null) { result=await helper.updateNote(note); }else{ result=await helper.insertNote(note); } if (note !=0) { __showAlertDialog('Status','Note Saved Sucessfully'); }else{ __showAlertDialog('status', 'problem solving note'); } } void __showAlertDialog(String title, String message) { AlertDialog alertDialog=AlertDialog( title: Text(title), content: Text(message), ); showDialog(context: context, builder: (_)=>alertDialog); } void updatePriorityAsInt(Object? valueSelectedByUser) { var value; switch (value) { case 'HIGH': note.Priority=1; break; case 'LOW': note.Priority=2; break; } } Future<void> _delete() async { moveToLastScreen(); if (note.id!=null) { __showAlertDialog('status', 'first add note'); return; } int result= await helper.deleteNote(note.id); if (result !=0) { __showAlertDialog('Status','Note deleted Sucessfully'); }else{ __showAlertDialog('status', '404 error'); } } getPriorityAsString(int value) { String ?priority; switch (value) { case 1: priority=_Priorities[0]; break; case 2: priority=_Priorities[1]; break; } return priority; } }
I am getting error like this.
- The getter 'title' isn't defined for the type 'TextTheme'. Try importing the library that defines 'title', correcting the name to the name of an existing getter, or defining a getter or field named 'title'.
- The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type. Try adding either a return or a throw statement at the end.
Please anyone can help me
-
Lars over 2 yearsplease add the lines for the errors.
-
Lars over 2 years@vinaym then please add the exact lines