在具有新包的类中找不到Flutter方法



我是新来的颤振。还是有些题目我想不通。

我创建了一个新的类和列表。我安装了一个名为粘性头的新软件包。当我尝试在类中使用这个包作为返回语句时,它给出了以下错误;

错误:找不到方法:"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网格视图应用

新游戏4网格视图应用

您需要在文件顶部导入包,如下所示:

import 'package:sticky_headers/sticky_headers.dart';

最新更新