Дочинил
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,13 +28,41 @@ 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: 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>?>(
|
child: FutureBuilder<List<CardData>?>(
|
||||||
future: data,
|
future: data,
|
||||||
builder: (context, snapshot) => SingleChildScrollView(
|
builder: (context, snapshot) => SingleChildScrollView(
|
||||||
@ -52,6 +79,10 @@ class Body extends StatelessWidget {
|
|||||||
: const CircularProgressIndicator(),
|
: const CircularProgressIndicator(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user