I want to remove duplicated Profilemodel by name only in items list , so I should get NO duplicated items in screen. I want to remove duplicated Profilemodel by name only in items list , so I should get NO duplicated items in screen.
I used items.toSet().toList() but its not work with my need.
Full code :
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
// Application name
title: 'Flutter Hello World',
// Application theme data, you can set the colors for the application as
// you want
theme: ThemeData(
primarySwatch: Colors.blue,
),
// A widget which will be started on application startup
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
List<Profilemodel> items = [
Profilemodel( age: 20 , name: 'Ahmed' ) ,
Profilemodel( age: 30 , name: 'Fatma' ),
Profilemodel( age: 15 , name: 'Ahmed' ),
Profilemodel( age: 15 , name: 'jon' ),
Profilemodel( age: 25 , name: 'Fatma' )];
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body : ListView.builder(
itemBuilder: (context, index){
return ListTile(
title: Text('${items[index].name}'),
);
},
itemCount: items.length,
)
);
}
}
class Profilemodel{
final String name;
final int age;
Profilemodel({this.name , this.age});
}

