Дочинил
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';
|
static const String _baseUrl = 'https://fortnite-api.com';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<CardData>?> loadData() async {
|
Future<List<CardData>?> loadData({String? q}) async {
|
||||||
try{
|
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);
|
final Response<dynamic> response = await _dio.get<Map<dynamic,dynamic>>(url);
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:untitled/data/repositories/fortnite_reppository.dart';
|
import 'package:untitled/data/repositories/fortnite_reppository.dart';
|
||||||
import 'package:untitled/data/repositories/mock_repository.dart';
|
|
||||||
|
|
||||||
import '../../domain/models/card.dart';
|
import '../../domain/models/card.dart';
|
||||||
import '../details_page/details_page.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});
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final data = FortniteRepository().loadData();
|
return Padding(
|
||||||
return Center(
|
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
|
||||||
child: FutureBuilder<List<CardData>?>(
|
child: Column(
|
||||||
future: data,
|
children: [
|
||||||
builder: (context, snapshot) => SingleChildScrollView(
|
Padding(
|
||||||
child: snapshot.hasData ? Column(
|
padding: const EdgeInsets.all(12),
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
child: CupertinoSearchTextField(
|
||||||
children: snapshot.data?.map((data) { return _Card.fromData(
|
controller: searchController,
|
||||||
data,
|
onSubmitted: (search) {
|
||||||
onLike: (String name, bool isLiked) =>
|
setState(() {
|
||||||
_showSnackBar(context, name, isLiked),
|
data = repo.loadData(q: search);
|
||||||
onTap: () => _navToDetails(context, data),
|
});
|
||||||
);
|
},
|
||||||
}).toList() ?? [],
|
),
|
||||||
)
|
),
|
||||||
: const CircularProgressIndicator(),
|
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