builder method
Implementation
@override
Widget? builder() {
return FutureBuilder<List<Token>>(
future: _tokenTypesFuture,
builder: (context, snapshot) {
if (snapshot.hasData) {
return SizedBox(
height: 74,
child: ListView.builder(
controller: _scrollController,
scrollDirection: Axis.horizontal,
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
final token = snapshot.data![index];
return Obx(() => Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: InkWell(
onTap: () {
selectedIndex.value = index;
selectedName.value = token.name;
logTokenClick(index, token);
// Get.forceAppUpdate();
},
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: selectedIndex.value == index
? LinearGradient(
colors: [
Colors.blueAccent.withOpacity(0.8),
Colors.lightBlueAccent.withOpacity(0.6),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
)
: null,
border: Border.all(
color: selectedIndex.value == index ? Colors.blueAccent : Colors.transparent,
width: 3,
),
),
child: CircleAvatar(
radius: 24,
backgroundImage: NetworkImage(snapshot.data![index].iconlink),
),
),
const SizedBox(height: 4), // 图标和文字间距
Flexible(
child: Text(
snapshot.data![index].name,
style: const TextStyle(fontSize: 12),
overflow: TextOverflow.ellipsis, // 防止文字溢出
),
),
],
),
),
)
);
},
),
);
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
}
return const CircularProgressIndicator();
},
);
}