Skip to content

Instantly share code, notes, and snippets.

@salsolatragus
Created October 29, 2019 12:34
Show Gist options
  • Save salsolatragus/d4c21d6e45be36f7ba9a2657b485cb3a to your computer and use it in GitHub Desktop.
Save salsolatragus/d4c21d6e45be36f7ba9a2657b485cb3a to your computer and use it in GitHub Desktop.
Minimal Example to Reproduce Flutter Framework Assertion Error
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: MyHome(),
);
}
}
class MyHome extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('minimal example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Press + to provoke the error',
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
showSearch(
context: context,
delegate: _TaskWithProjectSearchDelegate(
suggestions: [
TaskWithProject(718, 'A', 6600, 'zFriedhof', 'zFriedhof'),
TaskWithProject(718, 'A', 6605, 'zFriedhof', 'zFriedhof'),
TaskWithProject(718, 'A', 6611, 'zFriedhof', 'zFriedhof'),
],
)).then((task) {});
},
child: Icon(Icons.add),
),
);
}
}
class TaskWithProject extends Comparable<TaskWithProject> {
final int projectId;
final String projectName;
final int id;
final String taskList;
final String name;
TaskWithProject(this.projectId, this.projectName, this.id, this.taskList, this.name);
String get _compareString => '$projectName :: $taskList :: $name';
@override
int compareTo(TaskWithProject other) {
return this._compareString.compareTo(other._compareString);
}
}
class _TaskWithProjectSearchDelegate extends SearchDelegate<TaskWithProject> {
final List<TaskWithProject> suggestions;
_TaskWithProjectSearchDelegate({@required this.suggestions});
@override
List<Widget> buildActions(BuildContext context) => <Widget>[];
@override
Widget buildLeading(BuildContext context) {
return IconButton(
icon: AnimatedIcon(
icon: AnimatedIcons.menu_arrow,
progress: transitionAnimation,
),
onPressed: () {},
);
}
@override
Widget buildResults(BuildContext context) {
return null;
}
@override
Widget buildSuggestions(BuildContext context) {
return ListView(
children: this.suggestions.expand((TaskWithProject task) {
return <Widget>[
Text('[#${task.projectId}] ${task.projectName}'),
Text(task.taskList),
GestureDetector(
key: Key('${task.name}'), // <-- this causes the error (duplicated Key)
child: Text('[#${task.id}] ${task.name}')
),
];
}).toList(),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment