I am new to flutter i got stuck on this i dont know what to do please help. I have a searchdelegate search page I want to click on the results to view the full view details in next page. I used PHP as backend and json data into dart DataList view class here i imported the DATALIST.dart and api_service.dart to search in the json api to fetch data what i wanted. here i only search for names when i click on the names to show the full details in next page. all the data are from the json api.
i hope you undertand what i want to do.
import 'package:vms_1/DATALIST.dart';
import 'package:vms_1/Handout.dart';
import 'api_service.dart';
class SearchUser extends SearchDelegate {
FetchUserList _Datalist = FetchUserList();
@override
ThemeData appBarTheme(BuildContext context) {
final ThemeData theme = Theme.of(context);
return theme.copyWith(
primaryColor: theme.backgroundColor,
primaryIconTheme: theme.iconTheme,
primaryColorBrightness: theme.primaryColorBrightness,
primaryTextTheme: theme.primaryTextTheme,
);
}
@override
List<Widget> buildActions(BuildContext context) {
return [
IconButton(
color: Colors.white,
onPressed: () {
query = '';
},
icon: Icon(Icons.close))
];
}
@override
Widget buildLeading(BuildContext context) {
return IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(Icons.arrow_back),
);
}
@override
Widget buildResults(BuildContext context) {
return Container(
width: double.infinity,
decoration: const BoxDecoration(
gradient: const LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomRight,
colors: [
Colors.deepPurple,
Colors.lightBlueAccent,
]),
),
child: FutureBuilder<List<Datalist>>(
future: _Datalist.getDatalist(query: query),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
List<Datalist>? data = snapshot.data;
return ListView.builder(
itemCount: data?.length,
itemBuilder: (context, index) {
final emp = data![index];
return Container(
margin: EdgeInsets.all(10),
child: Card(
margin: const EdgeInsets.all(0),
elevation: 2.0,
child: ListTile(
title: Text('${data?[index].name}'),
subtitle: Text('${data?[index].email}'),
trailing: Icon(Icons.arrow_forward),
onTap: () {
Navigator.of(context).push(
new MaterialPageRoute(
builder: (BuildContext context) => new handout(),
),
);
},
),
),
);
});
}),
);
}
@override
Widget buildSuggestions(BuildContext context) {
return Scaffold(
body: Container(
width: double.infinity,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomRight,
colors: [
Colors.deepPurple,
Colors.lightBlueAccent,
]),
),
child: FutureBuilder<List<Datalist>>(
future: _Datalist.getDatalist(query: query),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
List<Datalist>? data = snapshot.data;
return ListView.builder(
itemCount: data?.length,
itemBuilder: (context, index) {
final emp = data![index];
return Container(
margin: EdgeInsets.all(10),
child: Card(
margin: const EdgeInsets.all(0),
elevation: 2.0,
child: ListTile(
title: Text('${data?[index].name}'),
subtitle: Text('${data?[index].email}'),
trailing: Icon(Icons.arrow_forward),
onTap: () { },
),
),
);
});
}),
),
);
}
}
here I want to show the selected item to be shown on handout page how to pass data to the next page to show the employee full details.
CodePudding user response:
You possibly want to Pass arguments to a named route , also have a look at e.g. Passing data between screens in Flutter - hope that helps.
CodePudding user response:
Consider following the FLutter Docs on passing data to routes using https://docs.flutter.dev/cookbook/navigation/passing-data or https://docs.flutter.dev/cookbook/navigation/navigate-with-arguments