我是 Flutter 的初学者,我是第一次使用 Futurebuilder 和 provider。最后,我创建了一个添加地点的应用程序。使用下面的代码,我几乎已经实现了该应用程序。但是现在出现了一个小问题。当应用程序从提供者获取数据时,它会显示浮动操作按钮。我不希望这种情况发生。有没有办法在获取数据时隐藏浮动操作按钮并在从数据库获取数据后将其显示给用户?
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import './add_place_screen.dart';
import '../providers/great_places.dart';
import './place_detail_screen.dart';
class PlacesListScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Your Places'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.add),
onPressed: () {
Navigator.of(context).pushNamed(AddPlaceScreen.routeName);
},
),
],
),
body: FutureBuilder(
future: Provider.of<GreatPlaces>(context, listen: false)
.fetchAndSetPlaces(),
builder: (ctx, snapshot) => snapshot.connectionState ==
ConnectionState.waiting
? Center(
child: CircularProgressIndicator(),
)
: Consumer<GreatPlaces>(
child: Center(
child: const Text('Got no places yet, start adding some!'),
),
builder: (ctx, greatPlaces, ch) => greatPlaces.items.length <= 0
? ch
: ListView.builder(
itemCount: greatPlaces.items.length,
itemBuilder: (ctx, i) => ListTile(
leading: CircleAvatar(
backgroundImage: FileImage(
greatPlaces.items[i].image,
),
),
title: Text(greatPlaces.items[i].title),
subtitle:
Text(greatPlaces.items[i].location.address),
onTap: () {
Navigator.of(context).pushNamed(
PlaceDetailScreen.routeName,
arguments: greatPlaces.items[i].id,
);
},
),
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
},
child: Icon(Icons.add),
),
);
}
}