Дочинил
This commit is contained in:
parent
539dc15d6d
commit
eb8e4b5483
@ -15,9 +15,12 @@ class FortniteRepository extends ApiInterface{
|
||||
static const String _baseUrl = 'https://fortnite-api.com';
|
||||
|
||||
@override
|
||||
Future<List<CardData>?> loadData() async {
|
||||
Future<List<CardData>?> loadData({String? q}) async {
|
||||
try{
|
||||
const String url = '$_baseUrl/v2/cosmetics/br/search/all?type=pickaxe';
|
||||
String url = '$_baseUrl/v2/cosmetics/br/search/all?type=pickaxe';
|
||||
if(q != null && q != ""){
|
||||
url += '&matchMethod=contains&name=$q';
|
||||
}
|
||||
|
||||
final Response<dynamic> response = await _dio.get<Map<dynamic,dynamic>>(url);
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:untitled/data/repositories/fortnite_reppository.dart';
|
||||
import 'package:untitled/data/repositories/mock_repository.dart';
|
||||
|
||||
import '../../domain/models/card.dart';
|
||||
import '../details_page/details_page.dart';
|
||||
@ -29,28 +28,60 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
}
|
||||
}
|
||||
|
||||
class Body extends StatelessWidget {
|
||||
class Body extends StatefulWidget {
|
||||
const Body({super.key});
|
||||
|
||||
@override
|
||||
State<Body> createState() => _BodyState();
|
||||
}
|
||||
class _BodyState extends State<Body> {
|
||||
|
||||
final searchController = TextEditingController();
|
||||
late Future<List<CardData>?> data;
|
||||
final repo = FortniteRepository();
|
||||
@override
|
||||
void initState() {
|
||||
data = repo.loadData();
|
||||
super.initState();
|
||||
}
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = FortniteRepository().loadData();
|
||||
return Center(
|
||||
child: FutureBuilder<List<CardData>?>(
|
||||
future: data,
|
||||
builder: (context, snapshot) => SingleChildScrollView(
|
||||
child: snapshot.hasData ? Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: snapshot.data?.map((data) { return _Card.fromData(
|
||||
data,
|
||||
onLike: (String name, bool isLiked) =>
|
||||
_showSnackBar(context, name, isLiked),
|
||||
onTap: () => _navToDetails(context, data),
|
||||
);
|
||||
}).toList() ?? [],
|
||||
)
|
||||
: const CircularProgressIndicator(),
|
||||
),
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: CupertinoSearchTextField(
|
||||
controller: searchController,
|
||||
onSubmitted: (search) {
|
||||
setState(() {
|
||||
data = repo.loadData(q: search);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: FutureBuilder<List<CardData>?>(
|
||||
future: data,
|
||||
builder: (context, snapshot) => SingleChildScrollView(
|
||||
child: snapshot.hasData ? Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: snapshot.data?.map((data) { return _Card.fromData(
|
||||
data,
|
||||
onLike: (String name, bool isLiked) =>
|
||||
_showSnackBar(context, name, isLiked),
|
||||
onTap: () => _navToDetails(context, data),
|
||||
);
|
||||
}).toList() ?? [],
|
||||
)
|
||||
: const CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user