Related
I got this unusual error while making my app. I am not exactly sure what it means to be honest. Also, It only does this error when I click on the checkbox for some reason. If you could please help me figure out what's wrong with the app that would be wonderful. Thank you.
tasks_list.dart
class TasksList extends StatelessWidget {
const TasksList({
Key? key,
required this.tasksList,
}) : super(key: key);
final List tasksList;
#override
Widget build(BuildContext context) {
return ListView.builder(
padding: const EdgeInsets.only(top: 20),
itemCount: tasksList.length,
itemBuilder: (context, index) {
var task = tasksList[index];
return TaskTile(task: task);
},
);
}
}
task_tile.dart
class TaskTile extends StatelessWidget {
const TaskTile({
Key? key,
required this.task,
}) : super(key: key);
final Task task;
#override
Widget build(BuildContext context) {
return Column(
children: [
const SizedBox(width: 4),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Row(
children: [
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(width: 10),
Flexible(
child: Column(
children: [
Text(
task.title,
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: const Color(0xFF89ABE3),
fontFamily: 'Source Sans Pro',
fontSize: 19,
decoration: task.isDone!
? TextDecoration.lineThrough
: null,
),
),
const SizedBox(
height: 5,
),
Text(
DateFormat().add_yMMMd().add_Hm().format(
DateTime.parse(task.date),
),
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontFamily: 'Source Sans Pro',
fontSize: 15,
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
color: Color(0xFF89ABE3),
),
),
],
),
),
const SizedBox(width: 10),
],
),
),
],
),
),
Row(
children: [
PopupMenu(
favouriteCallback: () => context.read<TasksBloc>().add(
MakeFavouriteTask(task: task),
),
task: task,
),
Transform.scale(
scale: 1.2,
child: Checkbox(
shape: const CircleBorder(
side: BorderSide(
width: 20,
),
),
side: const BorderSide(
color: Color(0xFF89ABE3),
),
activeColor: Colors.greenAccent,
value: task.isDone,
onChanged: task.isDeleted == false
? (value) {
context
.read<TasksBloc>()
.add(UpdateTask(task: task));
}
: null,
),
),
],
),
],
),
const SizedBox(width: 4),
const Divider(
thickness: 2,
),
],
);
}
}
Error Log
E/flutter (19323): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Unsupported operation: Cannot add to an unmodifiable list
E/flutter (19323): #0 UnmodifiableListMixin.insert (dart:_internal/list.dart:119:5)
E/flutter (19323): #1 TasksBloc._onUpdateTask (package:todo_list/blocs/tasks_bloc/tasks_bloc.dart:45:24)
E/flutter (19323): #2 Bloc.on.<anonymous closure>.handleEvent (package:bloc/src/bloc.dart:226:26)
E/flutter (19323): #3 Bloc.on.<anonymous closure> (package:bloc/src/bloc.dart:235:9)
E/flutter (19323): #4 _MapStream._handleData (dart:async/stream_pipe.dart:213:31)
E/flutter (19323): #5 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (19323): #6 _rootRunUnary (dart:async/zone.dart:1399:47)
E/flutter (19323): #7 _CustomZone.runUnary (dart:async/zone.dart:1300:19)
E/flutter (19323): #8 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
E/flutter (19323): #9 CastStreamSubscription._onData (dart:_internal/async_cast.dart:85:11)
E/flutter (19323): #10 _rootRunUnary (dart:async/zone.dart:1399:47)
E/flutter (19323): #11 _CustomZone.runUnary (dart:async/zone.dart:1300:19)
E/flutter (19323): #12 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
E/flutter (19323): #13 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (19323): #14 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (19323): #15 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (19323): #16 _WhereStream._handleData (dart:async/stream_pipe.dart:195:12)
E/flutter (19323): #17 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (19323): #18 _rootRunUnary (dart:async/zone.dart:1407:13)
E/flutter (19323): #19 _CustomZone.runUnary (dart:async/zone.dart:1300:19)
E/flutter (19323): #20 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
E/flutter (19323): #21 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (19323): #22 _DelayedData.perform (dart:async/stream_impl.dart:515:14)
E/flutter (19323): #23 _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11)
E/flutter (19323): #24 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591:7)
E/flutter (19323): #25 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (19323): #26 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
E/flutter (19323):
E/flutter (19323): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Unsupported operation: Cannot add to an unmodifiable list
E/flutter (19323): #0 UnmodifiableListMixin.insert (dart:_internal/list.dart:119:5)
E/flutter (19323): #1 TasksBloc._onUpdateTask (package:todo_list/blocs/tasks_bloc/tasks_bloc.dart:45:24)
E/flutter (19323): #2 Bloc.on.<anonymous closure>.handleEvent (package:bloc/src/bloc.dart:226:26)
E/flutter (19323): #3 Bloc.on.<anonymous closure> (package:bloc/src/bloc.dart:235:9)
E/flutter (19323): #4 _MapStream._handleData (dart:async/stream_pipe.dart:213:31)
E/flutter (19323): #5 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (19323): #6 _rootRunUnary (dart:async/zone.dart:1399:47)
E/flutter (19323): #7 _CustomZone.runUnary (dart:async/zone.dart:1300:19)
E/flutter (19323): #8 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
E/flutter (19323): #9 CastStreamSubscription._onData (dart:_internal/async_cast.dart:85:11)
E/flutter (19323): #10 _rootRunUnary (dart:async/zone.dart:1399:47)
E/flutter (19323): #11 _CustomZone.runUnary (dart:async/zone.dart:1300:19)
E/flutter (19323): #12 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
E/flutter (19323): #13 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (19323): #14 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (19323): #15 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (19323): #16 _WhereStream._handleData (dart:async/stream_pipe.dart:195:12)
E/flutter (19323): #17 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (19323): #18 _rootRunUnary (dart:async/zone.dart:1407:13)
E/flutter (19323): #19 _CustomZone.runUnary (dart:async/zone.dart:1300:19)
E/flutter (19323): #20 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
E/flutter (19323): #21 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (19323): #22 _DelayedData.perform (dart:async/stream_impl.dart:515:14)
E/flutter (19323): #23 _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11)
E/flutter (19323): #24 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591:7)
E/flutter (19323): #25 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (19323): #26 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
E/flutter (19323):
E/flutter (19323): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Unsupported operation: Cannot add to an unmodifiable list
E/flutter (19323): #0 UnmodifiableListMixin.insert (dart:_internal/list.dart:119:5)
E/flutter (19323): #1 TasksBloc._onUpdateTask (package:todo_list/blocs/tasks_bloc/tasks_bloc.dart:45:24)
E/flutter (19323): #2 Bloc.on.<anonymous closure>.handleEvent (package:bloc/src/bloc.dart:226:26)
E/flutter (19323): #3 Bloc.on.<anonymous closure> (package:bloc/src/bloc.dart:235:9)
E/flutter (19323): #4 _MapStream._handleData (dart:async/stream_pipe.dart:213:31)
E/flutter (19323): #5 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (19323): #6 _rootRunUnary (dart:async/zone.dart:1399:47)
E/flutter (19323): #7 _CustomZone.runUnary (dart:async/zone.dart:1300:19)
E/flutter (19323): #8 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
E/flutter (19323): #9 CastStreamSubscription._onData (dart:_internal/async_cast.dart:85:11)
E/flutter (19323): #10 _rootRunUnary (dart:async/zone.dart:1399:47)
E/flutter (19323): #11 _CustomZone.runUnary (dart:async/zone.dart:1300:19)
E/flutter (19323): #12 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
E/flutter (19323): #13 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (19323): #14 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter (19323): #15 _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter (19323): #16 _WhereStream._handleData (dart:async/stream_pipe.dart:195:12)
E/flutter (19323): #17 _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter (19323): #18 _rootRunUnary (dart:async/zone.dart:1407:13)
E/flutter (19323): #19 _CustomZone.runUnary (dart:async/zone.dart:1300:19)
E/flutter (19323): #20 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1209:7)
E/flutter (19323): #21 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (19323): #22 _DelayedData.perform (dart:async/stream_impl.dart:515:14)
E/flutter (19323): #23 _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11)
E/flutter (19323): #24 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:591:7)
E/flutter (19323): #25 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (19323): #26 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
tasks_bloc.dart
class TasksBloc extends HydratedBloc<TasksEvent, TasksState> {
TasksBloc() : super(const TasksState()) {
on<AddTask>(_onAddTask);
on<UpdateTask>(_onUpdateTask);
on<RemoveTask>(_onRemoveTask);
on<DeleteTask>(_onDeleteTask);
on<MakeFavouriteTask>(_onMakeFavouriteTask);
on<EditTask>(_onEditTask);
on<RestoreTask>(_onRestoreTask);
on<DeleteAllTasks>(_onDeleteAllTasks);
}
void _onAddTask(AddTask event, Emitter<TasksState> emitter) {
final state = this.state;
emitter(
TasksState(
pendingTasks: List.from(state.pendingTasks)..add(event.task),
completedTasks: state.completedTasks,
favouriteTasks: state.favouriteTasks,
deletedTasks: state.deletedTasks,
),
);
}
void _onUpdateTask(UpdateTask event, Emitter<TasksState> emit) {
final state = this.state;
final task = event.task;
List<Task> pendingTasks = state.pendingTasks;
List<Task> completedTasks = state.completedTasks;
List<Task> favouriteTasks = state.favouriteTasks;
if (task.isDone == false) {
if (task.isFavourite == false) {
pendingTasks = List.from(pendingTasks)..remove(task);
completedTasks.insert(0, task.copyWith(isDone: true));
} else {
var taskIndex = favouriteTasks.indexOf(task);
pendingTasks = List.from(pendingTasks)..remove(task);
completedTasks.insert(0, task.copyWith(isDone: true));
favouriteTasks = List.from(favouriteTasks)
..remove(task)
..insert(taskIndex, task.copyWith(isDone: true));
}
} else {
if (task.isFavourite == false) {
completedTasks = List.from(completedTasks)..remove(task);
pendingTasks = List.from(pendingTasks)
..insert(0, task.copyWith(isDone: false));
} else {
var taskIndex = favouriteTasks.indexOf(task);
completedTasks = List.from(completedTasks)..remove(task);
pendingTasks = List.from(pendingTasks)
..insert(0, task.copyWith(isDone: false));
favouriteTasks = List.from(favouriteTasks)
..remove(task)
..insert(taskIndex, task.copyWith(isDone: false));
}
}
emit(TasksState(
pendingTasks: pendingTasks,
completedTasks: completedTasks,
favouriteTasks: favouriteTasks,
deletedTasks: state.deletedTasks,
));
}
void _onRemoveTask(RemoveTask event, Emitter<TasksState> emitter) {
final state = this.state;
emitter(
TasksState(
pendingTasks: state.pendingTasks,
completedTasks: state.completedTasks,
favouriteTasks: state.favouriteTasks,
deletedTasks: List.from(state.deletedTasks)..remove(event.task),
),
);
}
void _onDeleteTask(DeleteTask event, Emitter<TasksState> emitter) {
final state = this.state;
emitter(
TasksState(
pendingTasks: List.from(state.pendingTasks)..remove(event.task),
completedTasks: List.from(state.completedTasks)..remove(event.task),
favouriteTasks: List.from(state.favouriteTasks)..remove(event.task),
deletedTasks: List.from(state.deletedTasks)
..add(
event.task.copyWith(isDeleted: true),
),
),
);
}
void _onMakeFavouriteTask(
MakeFavouriteTask event, Emitter<TasksState> emitter) {
final state = this.state;
List<Task> pendingTasks = state.pendingTasks;
List<Task> completedTasks = state.completedTasks;
List<Task> favouriteTasks = state.favouriteTasks;
if (event.task.isDone == false) {
if (event.task.isFavourite == false) {
var taskIndex = pendingTasks.indexOf(event.task);
pendingTasks = List.from(pendingTasks)
..remove(event.task)
..insert(
taskIndex,
event.task.copyWith(isFavourite: true),
);
favouriteTasks.insert(0, event.task.copyWith(isFavourite: true));
} else {
var taskIndex = pendingTasks.indexOf(event.task);
pendingTasks = List.from(pendingTasks)
..remove(event.task)
..insert(
taskIndex,
event.task.copyWith(isFavourite: false),
);
favouriteTasks.remove(event.task);
}
} else {
if (event.task.isFavourite == false) {
var taskIndex = completedTasks.indexOf(event.task);
completedTasks = List.from(completedTasks)
..remove(event.task)
..insert(
taskIndex,
event.task.copyWith(isFavourite: true),
);
favouriteTasks.insert(
0,
event.task.copyWith(isFavourite: true),
);
} else {
var taskIndex = completedTasks.indexOf(event.task);
completedTasks = List.from(completedTasks)
..remove(event.task)
..insert(
taskIndex,
event.task.copyWith(isFavourite: false),
);
favouriteTasks.remove(event.task);
}
}
emitter(
TasksState(
pendingTasks: pendingTasks,
completedTasks: completedTasks,
favouriteTasks: favouriteTasks,
deletedTasks: state.deletedTasks),
);
}
void _onEditTask(EditTask event, Emitter<TasksState> emitter) {
final state = this.state;
List<Task> favouriteTasks = state.favouriteTasks;
if (event.oldTask.isFavourite == true) {
favouriteTasks
..remove(event.oldTask)
..insert(
0,
event.currentTask,
);
}
emitter(
TasksState(
pendingTasks: List.from(state.pendingTasks)
..remove(event.oldTask)
..insert(0, event.currentTask),
completedTasks: state.completedTasks..remove(event.oldTask),
favouriteTasks: state.favouriteTasks,
deletedTasks: state.deletedTasks,
),
);
}
void _onRestoreTask(RestoreTask event, Emitter<TasksState> emitter) {
final state = this.state;
emitter(
TasksState(
deletedTasks: List.from(state.deletedTasks)..remove(event.task),
pendingTasks: List.from(state.pendingTasks)
..insert(
0,
event.task
.copyWith(isDeleted: false, isDone: false, isFavourite: false),
),
completedTasks: state.completedTasks,
favouriteTasks: state.favouriteTasks,
),
);
}
void _onDeleteAllTasks(DeleteAllTasks event, Emitter<TasksState> emitter) {
final state = this.state;
emitter(TasksState(
deletedTasks: List.from(state.deletedTasks)..clear(),
pendingTasks: state.pendingTasks,
completedTasks: state.completedTasks,
favouriteTasks: state.favouriteTasks,
));
}
#override
TasksState? fromJson(Map<String, dynamic> json) {
return TasksState.fromMap(json);
}
#override
Map<String, dynamic>? toJson(TasksState state) {
return state.toMap();
}
}
class TasksList extends StatelessWidget {
const TasksList({
Key? key,
required this.tasksList,
}) : super(key: key);
final List tasksList;
This tasksList is unmodifiable.
WHat you'd want to do is listen/get new data from the bloc
using context.watch<TasksBloc>().completedTasks
e.g
Sample usage.
class TasksList extends StatelessWidget {
const TasksList({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
final tasksList =context.watch<TasksBloc>().completedTasks;
return ListView.builder(
padding: const EdgeInsets.only(top: 20),
itemCount: tasksList.length,
itemBuilder: (context, index) {
var task = tasksList[index];
return TaskTile(task: task);
},
);
}
}
The following sample code does something unexpected:
import 'package:characters/characters.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key key}) : super(key: key);
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
print(' *** _MyHomePageState:_incrementCounter - ${this.hashCode}');
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Animated Text Kit Issue 168')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
AnimatedTextKit(
animatedText: TypewriterAnimatedText(
'Animated Text',
textStyle: const TextStyle(
fontSize: 45.0,
fontWeight: FontWeight.w900,
color: Colors.pink,
),
),
),
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
/// Animated Text that displays a [Text] element as if it is being typed one
/// character at a time.
class TypewriterAnimatedText {
/// Text for [Text] widget.
final String text;
/// [TextStyle] property for [Text] widget.
final TextStyle textStyle;
/// The [Duration] of the delay between the apparition of each characters
///
/// By default it is set to 30 milliseconds.
final Duration speed;
/// The Duration for the Animation Controller.
final Duration duration;
/// Same as [text] but as [Characters].
///
/// Need to use character length, not String length, to propertly support
/// Unicode and Emojis.
final Characters textCharacters;
TypewriterAnimatedText(
this.text, {
#required this.textStyle,
this.speed = const Duration(milliseconds: 30),
}) : assert(null != speed),
textCharacters = text.characters,
duration = speed * (text.characters.length);
Animation<int> _typewriterText;
void initAnimation(AnimationController controller) {
print(' >>> TypewriterAnimatedText:initAnimation - ${this.hashCode}');
_typewriterText = StepTween(
begin: 0,
end: textCharacters.length,
).animate(controller);
}
/// Widget showing partial text
Widget animatedBuilder(BuildContext context, Widget child) {
print(' >>> TypewriterAnimatedText:animatedBuilder - ${this.hashCode}');
final typewriterValue = _typewriterText.value;
final visibleString = '${textCharacters.take(typewriterValue)}_';
return Text(visibleString, style: textStyle);
}
}
/// Base class for Animated Text widgets.
class AnimatedTextKit extends StatefulWidget {
/// Text animation.
final TypewriterAnimatedText animatedText;
const AnimatedTextKit({
Key key,
#required this.animatedText,
}) : super(key: key);
/// Creates the mutable state for this widget. See [StatefulWidget.createState].
#override
_AnimatedTextKitState createState() => _AnimatedTextKitState();
}
class _AnimatedTextKitState extends State<AnimatedTextKit>
with TickerProviderStateMixin {
AnimationController _controller;
#override
void initState() {
print(' ^^^ _AnimatedTextKitState:initState - ${this.hashCode}');
super.initState();
final animatedText = widget.animatedText;
_controller = AnimationController(
duration: animatedText.duration,
vsync: this,
);
animatedText.initAnimation(_controller);
_controller.repeat();
}
#override
void dispose() {
_controller.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
print(' ^^^ _AnimatedTextKitState:build - ${this.hashCode}');
return AnimatedBuilder(
animation: _controller,
builder: widget.animatedText.animatedBuilder,
);
}
}
Run it and click on the Floating Action Button to increment the counter and the output will look something like this:
I/flutter (29275): ^^^ _AnimatedTextKitState:initState - 171683441
I/flutter (29275): >>> TypewriterAnimatedText:initAnimation - 936400533
I/flutter (29275): ^^^ _AnimatedTextKitState:build - 171683441
I/flutter (29275): >>> TypewriterAnimatedText:animatedBuilder - 936400533
I/chatty (29275): uid=10133(com.example.atk168) 1.ui identical 2 lines
I/flutter (29275): >>> TypewriterAnimatedText:animatedBuilder - 936400533
I/flutter (29275): >>> TypewriterAnimatedText:animatedBuilder - 936400533
I/chatty (29275): uid=10133(com.example.atk168) 1.ui identical 60 lines
I/flutter (29275): >>> TypewriterAnimatedText:animatedBuilder - 936400533
I/flutter (29275): *** _MyHomePageState:_incrementCounter - 220007591
I/flutter (29275): ^^^ _AnimatedTextKitState:build - 171683441
I/flutter (29275): >>> TypewriterAnimatedText:animatedBuilder - 280798896
I/flutter (29275): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (29275): The following NoSuchMethodError was thrown building AnimatedBuilder(animation:
I/flutter (29275): AnimationController#41b74(▶ 0.633), dirty, state: _AnimatedState#db314):
I/flutter (29275): The getter 'value' was called on null.
I/flutter (29275): Receiver: null
I/flutter (29275): Tried calling: value
I/flutter (29275):
I/flutter (29275): The relevant error-causing widget was:
I/flutter (29275): AnimatedBuilder file:///Users/anthony/github/awhitford/atk168/lib/main.dart:173:12
I/flutter (29275):
I/flutter (29275): When the exception was thrown, this was the stack:
I/flutter (29275): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
I/flutter (29275): #1 TypewriterAnimatedText.animatedBuilder (package:atk168/main.dart:121:45)
I/flutter (29275): #2 AnimatedBuilder.build (package:flutter/src/widgets/transitions.dart:1528:19)
I/flutter (29275): #3 _AnimatedState.build (package:flutter/src/widgets/transitions.dart:179:48)
I/flutter (29275): #4 StatefulElement.build (package:flutter/src/widgets/framework.dart:4825:27)
I/flutter (29275): #5 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4708:15)
I/flutter (29275): #6 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4880:11)
I/flutter (29275): #7 BuildOwner._runWithCurrentBuildTarget (package:flutter/src/widgets/framework.dart:2708:15)
I/flutter (29275): #8 Element.rebuild (package:flutter/src/widgets/framework.dart:4407:12)
I/flutter (29275): #9 StatefulElement.update (package:flutter/src/widgets/framework.dart:4912:5)
I/flutter (29275): #10 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #11 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4733:16)
I/flutter (29275): #12 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4880:11)
I/flutter (29275): #13 BuildOwner._runWithCurrentBuildTarget (package:flutter/src/widgets/framework.dart:2708:15)
I/flutter (29275): #14 Element.rebuild (package:flutter/src/widgets/framework.dart:4407:12)
I/flutter (29275): #15 StatefulElement.update (package:flutter/src/widgets/framework.dart:4912:5)
I/flutter (29275): #16 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #17 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5727:32)
I/flutter (29275): #18 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6327:17)
I/flutter (29275): #19 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #20 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6205:14)
I/flutter (29275): #21 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #22 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4733:16)
I/flutter (29275): #23 BuildOwner._runWithCurrentBuildTarget (package:flutter/src/widgets/framework.dart:2708:15)
I/flutter (29275): #24 Element.rebuild (package:flutter/src/widgets/framework.dart:4407:12)
I/flutter (29275): #25 StatelessElement.update (package:flutter/src/widgets/framework.dart:4789:5)
I/flutter (29275): #26 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #27 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4733:16)
I/flutter (29275): #28 BuildOwner._runWithCurrentBuildTarget (package:flutter/src/widgets/framework.dart:2708:15)
I/flutter (29275): #29 Element.rebuild (package:flutter/src/widgets/framework.dart:4407:12)
I/flutter (29275): #30 ProxyElement.update (package:flutter/src/widgets/framework.dart:5066:5)
I/flutter (29275): #31 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #32 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4733:16)
I/flutter (29275): #33 BuildOwner._runWithCurrentBuildTarget (package:flutter/src/widgets/framework.dart:2708:15)
I/flutter (29275): #34 Element.rebuild (package:flutter/src/widgets/framework.dart:4407:12)
I/flutter (29275): #35 ProxyElement.update (package:flutter/src/widgets/framework.dart:5066:5)
I/flutter (29275): #36 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #37 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5727:32)
I/flutter (29275): #38 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6327:17)
I/flutter (29275): #39 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #40 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4733:16)
I/flutter (29275): #41 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4880:11)
I/flutter (29275): #42 BuildOwner._runWithCurrentBuildTarget (package:flutter/src/widgets/framework.dart:2708:15)
I/flutter (29275): #43 Element.rebuild (package:flutter/src/widgets/framework.dart:4407:12)
I/flutter (29275): #44 StatefulElement.update (package:flutter/src/widgets/framework.dart:4912:5)
I/flutter (29275): #45 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #46 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4733:16)
I/flutter (29275): #47 BuildOwner._runWithCurrentBuildTarget (package:flutter/src/widgets/framework.dart:2708:15)
I/flutter (29275): #48 Element.rebuild (package:flutter/src/widgets/framework.dart:4407:12)
I/flutter (29275): #49 ProxyElement.update (package:flutter/src/widgets/framework.dart:5066:5)
I/flutter (29275): #50 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #51 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4733:16)
I/flutter (29275): #52 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4880:11)
I/flutter (29275): #53 BuildOwner._runWithCurrentBuildTarget (package:flutter/src/widgets/framework.dart:2708:15)
I/flutter (29275): #54 Element.rebuild (package:flutter/src/widgets/framework.dart:4407:12)
I/flutter (29275): #55 StatefulElement.update (package:flutter/src/widgets/framework.dart:4912:5)
I/flutter (29275): #56 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #57 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6205:14)
I/flutter (29275): #58 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #59 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4733:16)
I/flutter (29275): #60 BuildOwner._runWithCurrentBuildTarget (package:flutter/src/widgets/framework.dart:2708:15)
I/flutter (29275): #61 Element.rebuild (package:flutter/src/widgets/framework.dart:4407:12)
I/flutter (29275): #62 StatelessElement.update (package:flutter/src/widgets/framework.dart:4789:5)
I/flutter (29275): #63 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #64 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6205:14)
I/flutter (29275): #65 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #66 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4733:16)
I/flutter (29275): #67 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4880:11)
I/flutter (29275): #68 BuildOwner._runWithCurrentBuildTarget (package:flutter/src/widgets/framework.dart:2708:15)
I/flutter (29275): #69 Element.rebuild (package:flutter/src/widgets/framework.dart:4407:12)
I/flutter (29275): #70 StatefulElement.update (package:flutter/src/widgets/framework.dart:4912:5)
I/flutter (29275): #71 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #72 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4733:16)
I/flutter (29275): #73 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4880:11)
I/flutter (29275): #74 BuildOwner._runWithCurrentBuildTarget (package:flutter/src/widgets/framework.dart:2708:15)
I/flutter (29275): #75 Element.rebuild (package:flutter/src/widgets/framework.dart:4407:12)
I/flutter (29275): #76 StatefulElement.update (package:flutter/src/widgets/framework.dart:4912:5)
I/flutter (29275): #77 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #78 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4733:16)
I/flutter (29275): #79 BuildOwner._runWithCurrentBuildTarget (package:flutter/src/widgets/framework.dart:2708:15)
I/flutter (29275): #80 Element.rebuild (package:flutter/src/widgets/framework.dart:4407:12)
I/flutter (29275): #81 ProxyElement.update (package:flutter/src/widgets/framework.dart:5066:5)
I/flutter (29275): #82 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #83 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4733:16)
I/flutter (29275): #84 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4880:11)
I/flutter (29275): #85 BuildOwner._runWithCurrentBuildTarget (package:flutter/src/widgets/framework.dart:2708:15)
I/flutter (29275): #86 Element.rebuild (package:flutter/src/widgets/framework.dart:4407:12)
I/flutter (29275): #87 StatefulElement.update (package:flutter/src/widgets/framework.dart:4912:5)
I/flutter (29275): #88 Element.updateChild (package:flutter/src/widgets/framework.dart:3412:15)
I/flutter (29275): #89 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4733:16)
I/flutter (29275): #90 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4880:11)
I/flutter (29275): #91 BuildOwner._runWithCurrentBuildTarget (package:flutter/src/widgets/framework.dart:2708:15)
I/flutter (29275): #92 Element.rebuild (package:flutter/src/widgets/framework.dart:4407:12)
I/flutter (29275): #93 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2813:33)
I/flutter (29275): #94 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:899:21)
I/flutter (29275): #95 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:320:5)
I/flutter (29275): #96 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1119:15)
I/flutter (29275): #97 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1057:9)
I/flutter (29275): #98 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:973:5)
I/flutter (29275): #102 _invoke (dart:ui/hooks.dart:157:10)
I/flutter (29275): #103 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:253:5)
I/flutter (29275): #104 _drawFrame (dart:ui/hooks.dart:120:31)
I/flutter (29275): (elided 3 frames from dart:async)
I/flutter (29275):
I/flutter (29275): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (29275): Another exception was thrown: A RenderFlex overflowed by 99320 pixels on the bottom.
I/flutter (29275): >>> TypewriterAnimatedText:animatedBuilder - 280798896
I/flutter (29275): Another exception was thrown: NoSuchMethodError: The getter 'value' was called on null.
I/flutter (29275): >>> TypewriterAnimatedText:animatedBuilder - 280798896
Application finished.
Specifically, look closely at this:
I/flutter (29275): >>> TypewriterAnimatedText:animatedBuilder - 936400533
I/flutter (29275): *** _MyHomePageState:_incrementCounter - 220007591
I/flutter (29275): ^^^ _AnimatedTextKitState:build - 171683441
I/flutter (29275): >>> TypewriterAnimatedText:animatedBuilder - 280798896
I/flutter (29275): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (29275): The following NoSuchMethodError was thrown building AnimatedBuilder(animation:
I/flutter (29275): AnimationController#41b74(▶ 0.633), dirty, state: _AnimatedState#db314):
I/flutter (29275): The getter 'value' was called on null.
I/flutter (29275): Receiver: null
I/flutter (29275): Tried calling: value
I/flutter (29275):
I/flutter (29275): The relevant error-causing widget was:
I/flutter (29275): AnimatedBuilder file:///Users/anthony/github/awhitford/atk168/lib/main.dart:173:12
I/flutter (29275):
I/flutter (29275): When the exception was thrown, this was the stack:
I/flutter (29275): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
I/flutter (29275): #1 TypewriterAnimatedText.animatedBuilder (package:atk168/main.dart:121:45)
I/flutter (29275): #2 AnimatedBuilder.build (package:flutter/src/widgets/transitions.dart:1528:19)
I/flutter (29275): #3 _AnimatedState.build (package:flutter/src/widgets/transitions.dart:179:48)
I only have one TypewriterAnimatedText declaration. It is building TypewriterAnimatedText 936400533, which has been properly initialized, but after clicking the button, it starts building a new instance (280798896) that hasn't been initialized, and so _typewriterText is null, and calling .value on that triggers this issue.
What is going on? I'm expecting that build only runs after initState -- but that doesn't seem to be the case here? (Did I discover a Flutter Bug?)
This issue was a little tricky to reproduce. I received several complaints from Windows users, so it would seem that they were able to easily reproduce this. For myself, I was only able to reproduce this on my Mac after switching to the dev channel and testing on the Android emulator.
Error code
E/flutter (25456): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)]
Unhandled Exception: NoSuchMethodError: The method '[]' was called on
null. E/flutter (25456): Receiver: null E/flutter (25456): Tried
calling: E/flutter (25456): #0 Object.noSuchMethod
(dart:core-patch/object_patch.dart:53:5) E/flutter (25456): #1
_WeatherState.fetchLocationUpDate. (package:tast_project/screenes/screenweather.dart:31:27) E/flutter
(25456): #2 State.setState
(package:flutter/src/widgets/framework.dart:1148:30) E/flutter
(25456): #3 _WeatherState.fetchLocationUpDate
(package:tast_project/screenes/screenweather.dart:30:5) E/flutter
(25456): E/flutter (25456): #4
_WeatherState.initState (package:tast_project/screenes/screenweather.dart:42:5) E/flutter
(25456): #5 StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:4355:58) E/flutter
(25456): #6 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:4201:5) E/flutter (25456):
#7 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter
(25456): #8 Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12) E/flutter
(25456): #9 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:5445:14) E/flutter
(25456): #10 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3194:14) E/flutter
(25456): #11 Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12) E/flutter
(25456): #12 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:4243:16) E/flutter
(25456): #13 Element.rebuild
(package:flutter/src/widgets/framework.dart:3947:5) E/flutter (25456):
#14 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5) E/flutter (25456):
#15 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5) E/flutter (25456):
#16 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter
(25456): #17 Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12) E/flutter
(25456): #18 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:5445:14) E/flutter
(25456): #19 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3194:14) E/flutter
(25456): #20 Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12) E/flutter
(25456): #21 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:5445:14) E/flutter
(25456): #22 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3194:14) E/flutter
(25456): #23 Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12) E/flutter
(25456): #24 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:4243:16) E/flutter
(25456): #25 Element.rebuild
(package:flutter/src/widgets/framework.dart:3947:5) E/flutter (25456):
#26 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5) E/flutter (25456):
#27 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11) E/flutter
(25456): #28 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:4201:5) E/flutter (25456):
#29 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter
(25456): #30 Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12) E/flutter
(25456): #31 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:5445:14) E/flutter
(25456): #32 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3194:14) E/flutter
(25456): #33 Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12) E/flutter
(25456): #34 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:5445:14) E/flutter
(25456): #35 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3194:14) E/flutter
(25456): #36 Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12) E/flutter
(25456): #37 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:4243:16) E/flutter
(25456): #38 Element.rebuild
(package:flutter/src/widgets/framework.dart:3947:5) E/flutter (25456):
#39 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5) E/flutter (25456):
#40 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11) E/flutter
(25456): #41 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:4201:5) E/flutter (25456):
#42 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter
(25456): #43 Element.updateChild
(package:flutter/src/widgets/framework.dart:2988:12) E/flutter
(25456): #44 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.da
Flutter code weather
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'dart:convert';
class Weather extends StatefulWidget {
#override
_WeatherState createState() => _WeatherState();
}
const ipkay = '14f4090b86e2548527113ccac56a5ae4';
class _WeatherState extends State<Weather> {
var temp = 0;
String city='';
//var id = 4099194;
String location ;
var textEditingController = TextEditingController();
fetchSearch(String input) async {
http.Response response = await http.get(
"http://api.openweathermap.org/data/2.5/weather?units=metric&appid=14f4090b86e2548527113ccac56a5ae4&q=" + input);
var result = json.decode(response.body);
setState(() {
location =result['name'];
});}
fetchLocationUpDate()async{
http.Response response = await http.get(
'http://api.openweathermap.org/data/2.5/weather?units=metric&appid=14f4090b86e2548527113ccac56a5ae4&q=$location');
var result = json.decode(response.body);
setState(() {
temp =result['main']['temp'];
city =result['name'];
});}
glo(String city){
fetchSearch(city);
fetchLocationUpDate();}
#override
void initState() {
super.initState();
fetchLocationUpDate();}
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Colors.transparent,
body: SafeArea(
child: Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assetes/img/night.jpg',
),
fit: BoxFit.fill)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'${temp.toString()} C°',
style: TextStyle(color: Colors.white, fontSize: 30),
),
Text(
'$city',
style: TextStyle(color: Colors.white, fontSize: 30),
),
Card(
child: TextField(
onSubmitted: (String city) {
glo(city);
},
controller: textEditingController,
decoration: InputDecoration(
hintText: 'please entre city',
prefixIcon: Icon(Icons.search),
),
),
),
)
],
),
),
),
);
}
You can copy paste run full code below
Step 1: double temp = 0;
Step 2: glo need async and await
glo(String city) async {
await fetchSearch(city);
await fetchLocationUpDate();
}
Step 3: Check city exist or not
if (result["cod"] == 200) {
setState(() {
location = result['name'];
print("locaton $location");
});
}
working demo
full code
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'dart:convert';
class Weather extends StatefulWidget {
#override
_WeatherState createState() => _WeatherState();
}
const ipkay = '14f4090b86e2548527113ccac56a5ae4';
class _WeatherState extends State<Weather> {
double temp = 0;
//var id = 4099194;
String location;
var textEditingController = TextEditingController();
fetchSearch(String input) async {
http.Response response = await http.get(
"http://api.openweathermap.org/data/2.5/weather?units=metric&appid=14f4090b86e2548527113ccac56a5ae4&q=" +
input);
var result = json.decode(response.body);
print("fetchSearch ${response.body}");
if (result["cod"] == 200) {
setState(() {
location = result['name'];
print("locaton $location");
});
}
}
fetchLocationUpDate() async {
print("location to string ${location.toString()}");
http.Response response = await http.get(
'http://api.openweathermap.org/data/2.5/weather?units=metric&appid=14f4090b86e2548527113ccac56a5ae4&q=' +
location.toString());
print("LocationUpdate ${response.body}");
var result = json.decode(response.body);
if (result["cod"] == 200) {
setState(() {
temp = result['main']['temp'];
});
}
}
glo(String city) async {
await fetchSearch(city);
await fetchLocationUpDate();
}
#override
void initState() {
super.initState();
//fetchLocationUpDate();
}
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Colors.transparent,
body: SafeArea(
child: Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://picsum.photos/250?image=9',
),
fit: BoxFit.fill)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'${temp.toDouble()} C°',
style: TextStyle(color: Colors.white, fontSize: 30),
),
Card(
child: TextField(
onSubmitted: (String city) {
glo(city);
},
controller: textEditingController,
decoration: InputDecoration(
hintText: 'please entre city',
prefixIcon: Icon(Icons.search),
),
),
),
// RaisedButton(
// onPressed: () {
// glo();
// },
// )
],
),
),
),
);
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Weather(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
Im trying to play a video from the internet using VideoPlayerController.network() method but every single url that i try face with an error which is specified below :
Source error.
E/flutter ( 4250): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4, null)
E/flutter ( 4250): #0 ChewieController._initialize (package:chewie/src/chewie_player.dart:291:7)
E/flutter ( 4250): <asynchronous suspension>
E/flutter ( 4250): #1 new ChewieController (package:chewie/src/chewie_player.dart:197:5)
E/flutter ( 4250): #2 _ChewieListState.initState (package:flutterappvideoandshit/screens/chewie_list.dart:20:25)
E/flutter ( 4250): #3 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4640:58)
E/flutter ( 4250): #4 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #5 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #6 Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #7 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5830:14)
E/flutter ( 4250): #8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #9 Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #10 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5830:14)
E/flutter ( 4250): #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #13 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #14 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #15 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #16 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #17 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #18 Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #19 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #20 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #21 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #22 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #23 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #24 Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #25 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #26 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
E/flutter ( 4250): #27 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #28 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #29 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4666:11)
E/flutter ( 4250): #30 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #31 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #32 Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #33 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16)
E/flutter ( 4250): #34 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
E/flutter ( 4250): #35 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5)
E/flutter ( 4250): #36 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5)
E/flutter ( 4250): #37 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14)
E/flutter ( 4250): #38 Element.updateChild (package:flutter/src/widgets/framework.dart:3214:18)
E/flutter ( 4250): #39 SliverMultiBoxAdaptorElement.updateChild (package:flutter/src/widgets/sliver.dart:1147:36)
E/flutter ( 4250): #40 SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1132:20)
E/flutter ( 4250): #41 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2607:19)
and here is my code :
import 'package:video_player/video_player.dart';
import 'package:chewie/chewie.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Video Player"),
),
body: ListView(
children: <Widget>[
ChewieList(
videoPlayerController: VideoPlayerController.asset('assets/videos/soccer.mp4'),
looping: true,
),
ChewieList(
videoPlayerController: VideoPlayerController.network(
'https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),
),
/*
ChewieList(
videoPlayerController: VideoPlayerController.network(
'http://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),
)
*/
],
),
);
}
}
class ChewieList extends StatefulWidget {
ChewieList({#required this.videoPlayerController,this.looping,Key key,}) : super(key:key);
final VideoPlayerController videoPlayerController;
final bool looping;
#override
_ChewieListState createState() => _ChewieListState();
}
class _ChewieListState extends State<ChewieList> {
ChewieController _chewieController;
#override
void initState() {
// TODO: implement initState
super.initState();
_chewieController = ChewieController(
videoPlayerController: widget.videoPlayerController,
aspectRatio: 16/9,
autoInitialize: true,
looping: widget.looping,
errorBuilder: (context,errMsg){
return Center(
child:Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.warning,color: Colors.yellowAccent,),
Text("!خطایی در برقراری ارتباط رخ داده است",style: TextStyle(color: Colors.white),)
],
),
);
}
);
}
#override
void dispose() {
// TODO: implement dispose
super.dispose();
widget.videoPlayerController.dispose();
_chewieController.dispose();
}
#override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(8.0),
child: Chewie(
controller: _chewieController,
),
);
}
}
it's driving me crazy!!!!
guys please help me .
You are using the wrong url. The url you posted is not the real video url but is only a redirect url.
Try with:
VideoPlayerController.network('https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'),
(Remember that iOS simulators and other does not always support video playing.)
I follow the steps of a packpub intermediate course, and the code does not work properly. I need some help to understand the Exception.
The following assertion was thrown while handling a gesture:
type 'List<dynamic>' is not a subtype of type 'List<PopupMenuEntry<Animals>>'
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new MyApp(),
));
}
class MyApp extends StatefulWidget {
#override
_State createState() => new _State();
}
enum Animals{Cat, Dog, Bird, Lizard, Fish}
class _State extends State<MyApp> {
Animals _selected = Animals.Cat;
String _value = 'Make a Selection';
List _items = new List();
#override
void initState() {
for(Animals animal in Animals.values) {
_items.add(new PopupMenuItem(
child: new Text(_getDisplay(animal),),
value: animal,
));
}
}
void _onSelected(Animals animal){
setState((){
_selected = animal;
_value = 'You Selected ${_getDisplay(animal)}';
});
}
String _getDisplay(Animals animal) {
int index = animal.toString().indexOf('.');
index++;
return animal.toString().substring(index);
}
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Name here'),
),
body: new Container(
padding: new EdgeInsets.all(32.0),
child: new Center(
child: new Row(
children: <Widget>[
new Container(
padding: new EdgeInsets.all(5.0),
child: new Text(_value),
),
new PopupMenuButton<Animals>(
child: new Icon(Icons.input),
initialValue: Animals.Cat,
onSelected: _onSelected,
itemBuilder: (BuildContext context) {
return _items;
}
)
],
),
),
),
);
}
}
When I press the PopupMenuButton the list does not appear,
and this is what I get on the console:
I/flutter (10194): ══╡ EXCEPTION CAUGHT BY GESTURE ╞══════════════════════════════════════════════════════════════════
I/flutter (10194): The following assertion was thrown while handling a gesture: I/flutter (10194): type 'List' is not a subtype of type 'List>'
I/flutter (10194): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (10194): more information in this error message to help you determine and fix the underlying cause.
I/flutter (10194): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (10194):
https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter (10194): When the exception was thrown, this was the stack:
I/flutter (10194): #0 _State.build. (package:widget4/main.dart:67:21)
I/flutter (10194): #1 _PopupMenuButtonState.showButtonMenu (package:flutter/src/material/popup_menu.dart:900:21)
I/flutter (10194): #2 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:513:14)
I/flutter (10194): #3 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:568:30)
I/flutter (10194): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:120:24)
I/flutter (10194): #5 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
I/flutter (10194): #6 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7)
I/flutter (10194): #7 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:369:9)
I/flutter (10194): #8 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
I/flutter (10194): #9 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
I/flutter (10194): #10
_WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:214:19)
I/flutter (10194): #11
_WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:192:22)
I/flutter (10194): #12
_WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:149:7)
I/flutter (10194): #13
_WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
I/flutter (10194): #14
_WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
I/flutter (10194): #18 _invoke1 (dart:ui/hooks.dart:223:10)
I/flutter (10194): #19 _dispatchPointerDataPacket (dart:ui/hooks.dart:144:5)
I/flutter (10194): (elided 3 frames from package dart:async)
I/flutter (10194): Handler: onTap
I/flutter (10194): Recognizer:
I/flutter (10194): TapGestureRecognizer#7540f(debugOwner: GestureDetector, state: accepted, won arena, finalPosition:
I/flutter (10194): Offset(156.5, 334.8), sent tap down) ══════════════════════════════════════════════════════════════
I/flutter (10194): Another exception was thrown: type 'List' is not a subtype of type 'List>'