'The following StateError was thrown while executing callbacks for FrameTiming:
I have the Flutter 2.10.5 version of android studio, the app works fine when I run it, but on terminal showed this messages, what should I do? I got this error from terminal:
Performing hot restart...
Syncing files to device sdk gphone x86...
Restarted application in 1,150ms.
======== Exception caught by Flutter framework =====================================================
The following StateError was thrown while executing callbacks for FrameTiming:
Bad state: Future already completed
When the exception was thrown, this was the stack:
#1 WidgetsBinding.drawFrame.<anonymous closure> (package:flutter/src/widgets/binding.dart:872:30)
#2 SchedulerBinding._executeTimingsCallbacks (package:flutter/src/scheduler/binding.dart:286:19)
#6 _invoke1 (dart:ui/hooks.dart:170:10)
#7 PlatformDispatcher._reportTimings (dart:ui/platform_dispatcher.dart:494:5)
#8 _reportTimings (dart:ui/hooks.dart:110:31)
(elided 4 frames from dart:async)
The TimingsCallback that gets executed was: Closure: (List<FrameTiming>) => void
====================================================================================================
This is my code:
home_screen.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_golang_yt/colors/app_colors.dart';
import 'package:flutter_golang_yt/widgets/button_widget.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
width: double.maxFinite,
height: double.maxFinite,
padding: const EdgeInsets.only(left: 20, right: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RichText(
text: TextSpan(
text: "Hello",
style: TextStyle(
color: AppColors.mainColor,
fontSize: 60,
fontWeight: FontWeight.bold
),
children: [
TextSpan(
text: "\nGet up early!",
style: TextStyle(
color: AppColors.smallTextColor,
fontSize: 30,
))
]
),
),
SizedBox(height: MediaQuery.of(context).size.height/2.5,),
ButtonWidget(backgroundcolor: AppColors.mainColor,
text: "Add Task",
textColor: Colors.white),
const SizedBox(height: 20,),
ButtonWidget(backgroundcolor: Colors.white,
text: "View All",
textColor: AppColors.smallTextColor)
],
),
decoration: const BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
"assets/welcome.jpg"
)
)
),
),
);
}
}
main.dart
import 'package:flutter/material.dart';
import 'package:flutter_golang_yt/screens/add_task.dart';
import 'package:flutter_golang_yt/screens/all_tasks.dart';
import 'package:flutter_golang_yt/screens/home_screen.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const AllTasks(),
);
}
}
add_task.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_golang_yt/colors/app_colors.dart';
import 'package:flutter_golang_yt/widgets/button_widget.dart';
import 'package:flutter_golang_yt/widgets/textfield_widget.dart';
class AddTask extends StatelessWidget {
const AddTask({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
TextEditingController nameController = TextEditingController();
TextEditingController detailController = TextEditingController();
return Scaffold(
body: Container(
width: double.maxFinite,
height: double.maxFinite,
padding: const EdgeInsets.only(left: 20, right: 20),
decoration: const BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
"assets/addtask1.jpg"
)
)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
const SizedBox(height: 60,),
IconButton(onPressed: (){},
icon: Icon(Icons.arrow_back,
color: AppColors.secondaryColor,
))
],
),
Column(
children: [
TextFieldWidget(textController: nameController,
hintText: "Task name",
borderRadius: 30),
const SizedBox(height: 20,),
TextFieldWidget(textController: detailController,
hintText: "Task detail",
borderRadius: 15,
maxLines: 3,),
const SizedBox(height: 20,),
ButtonWidget(backgroundcolor: AppColors.mainColor,
text: "Add", textColor: Colors.white)
],
),
SizedBox(
height: MediaQuery.of(context).size.height/6,
)
],
),
),
);
}
}
task_widget.dart
import 'package:flutter/cupertino.dart';
class TaskWidget extends StatelessWidget {
final String text;
final Color? color;
const TaskWidget({Key? key, required this.text,
required this.color}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
width: double.maxFinite,
height: MediaQuery.of(context).size.height/14,
decoration: BoxDecoration(
color: Color(0xFFedf0f8),
borderRadius: BorderRadius.circular(10)
),
child: Center(
child: Text(text, style: TextStyle(
fontSize: 20,
color: color,
),),
),
);
}
}
all_tasks.dart
import 'package:flutter/material.dart';
import 'package:flutter_golang_yt/colors/app_colors.dart';
import 'package:flutter_golang_yt/widgets/task_widget.dart';
class AllTasks extends StatelessWidget {
const AllTasks({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
List myData =[
"Disciplina tu cerebro",
"rendirse es perder"
];
return Scaffold(
backgroundColor: Colors.white,
body: Column(
children: [
Container(
padding: const EdgeInsets.only(left: 20, top: 60),
alignment: Alignment.topLeft,
child: Icon(Icons.arrow_back, color: AppColors.secondaryColor,),
width: double.maxFinite,
height: MediaQuery.of(context).size.height/3.2,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
"assets/header1.jpg"
)
)
),
),
Container(
padding: const EdgeInsets.only(left: 20, right: 20),
child: Row(
children: [
Icon(Icons.home, color: AppColors.secondaryColor,),
SizedBox(width: 10,),
Container(
child: Icon(Icons.add, color: Colors.white,size: 20,),
width: 25,
height: 25,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.5),
color: Colors.black
),
),
Expanded(child: Container()),
Icon(Icons.calendar_month_sharp, color: AppColors.secondaryColor,),
SizedBox(width: 10,),
Text("2", style: TextStyle(
fontSize: 20,
color: AppColors.secondaryColor
),)
],
),
),
Flexible(
child: ListView.builder(
itemCount: myData.length,
itemBuilder: (context, index){
return Dismissible(
onDismissed: (DismissDirection direction) {
print("after dismiss");
},
confirmDismiss: (DismissDirection direction)async{
print("confirming");
return false;
},
key: ObjectKey(index),
child: Container(
margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10),
child: TaskWidget(
text: myData[index],
color: Colors.blueGrey,
),
),
);
}),
)
],
),
);
}
}
textfield_widget.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../colors/app_colors.dart';
class TextFieldWidget extends StatelessWidget {
final TextEditingController textController;
final String hintText;
final double? borderRadius;
final int? maxLines;
const TextFieldWidget({Key? key,
required this.textController,
required this.hintText,
this.borderRadius=30,
this.maxLines=1}) : super(key: key);
@override
Widget build(BuildContext context) {
return TextField(
maxLines: maxLines,
controller: textController,
decoration: InputDecoration(
filled: true,
fillColor: AppColors.textHolder,
hintText: hintText,
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(borderRadius!),
borderSide: const BorderSide(
color:Colors.white,
width: 1
)
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(borderRadius!),
borderSide: BorderSide(
color:Colors.white,
width: 1
)
)
),
);
}
}
button_widget.dart
class ButtonWidget extends StatelessWidget {
final Color backgroundcolor;
final String text;
final Color textColor;
ButtonWidget({Key? key,
required this.backgroundcolor,
required this.text,
required this.textColor}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
width: double.maxFinite,
height: MediaQuery.of(context).size.height/14,
decoration: BoxDecoration(
color: backgroundcolor,
borderRadius: BorderRadius.circular(40)
),
child: Center(
child: Text(text, style: TextStyle(
fontSize: 24,color: textColor
),),
),
);
}
}
Also have pubspec.yaml
name: flutter_golang_yt
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.16.1 <3.0.0"
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^1.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
