Я новичок во флаттере. Тем не менее я не могу понять некоторые темы.
Я создал новый класс и список. Я установил новый пакет, который называется липкие заголовки. Когда я пытаюсь использовать этот пакет как оператор возврата в классе, он выдает ошибку ниже:
Ошибка: Метод не найден: 'StickyHeader'.
Мои коды приведены ниже;
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:getflutter/components/loader/gf_loader.dart';
import 'package:getflutter/types/gf_loader_type.dart';
import 'package:http/http.dart' as http;
import 'package:sticky_headers/sticky_headers.dart';
class Application {
String title;
String score;
String icon;
String googleplay;
String slug;
String category;
String link;
Application(
{String title,
String icon,
String score,
String category,
String link,
String googleplay,
String slug})
: this.title= title,
this.icon = icon,
this.category= category,
this.slug = slug,
this.googleplay = googleplay,
this.link= link,
this.score = score.toString();
Application.fromJSON(Map<String, dynamic> parsedJson)
: title= parsedJson['title'],
icon = parsedJson['icon '],
link= parsedJson['link'],
category= parsedJson['category'],
googleplay = parsedJson['googleplay_id'],
score = parsedJson['score'].toString(),
slug = parsedJson['slug'];
}
class HomepageView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FutureBuilder<List<Uygulama>>(
future: _fetchJobs(),
builder: (context, snapshot) {
if (snapshot.hasData) {
List<Application> data = snapshot.data;
return gridHeader(data);
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return GFLoader(type: GFLoaderType.circle);
},
);
}
Future<List<Application>> _fetchJobs() async {
final jobsListAPIUrl = 'jsonurl';
final response = await http.get(jobsListAPIUrl);
if (response.statusCode == 200) {
List jsonResponse = json.decode(response.body);
return jsonResponse
.map((Application) => new Application.fromJSON(Application))
.toList();
} else {
throw Exception('Failed to load jobs from API');
}
}
Widget gridHeader(data) {
return new ListView.builder(
itemCount: data.length,
itemBuilder: (context, index) {
return StickyHeader(
header: Container(
height: 38.0,
color: Colors.white,
padding: EdgeInsets.symmetric(horizontal: 12.0),
alignment: Alignment.centerLeft,
child: Text(
"New Apps",
style: const TextStyle(
color: Colors.purple,
fontSize: 20,
fontWeight: FontWeight.bold),
),
),
content: Container(
child: GridView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: 8,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 1,
),
itemBuilder: (contxt, indx) {
return Card(
margin: EdgeInsets.all(4.0),
color: Colors.purpleAccent,
child: Padding(
padding: const EdgeInsets.only(
left: 12.0, top: 6.0, bottom: 2.0),
child: Center(
child: Text(
data[indx],
style: TextStyle(fontSize: 14, color: Colors.black54),
)),
),
);
},
),
),
);
},
shrinkWrap: true,
);
}
}
Я хочу сделать экран домашней страницы прокручиваемым с несколькими сетками с собственными заголовками;
Пример:
Новое приложение сетки 4 приложения
Лучшее приложение 4 gridview
Новые игры 4 gridview