Эй, ребята, мне нужно отредактировать страницу моей корзины, но мне нужно динамически обновлять и обновлять sh некоторые данные, поэтому я просто изменил свой виджет на статусный виджет, но он ничего не показывает. Кто-нибудь знает, в чем проблема? Также я могу видеть данные, когда я использую виджет Statelles. Я использую mysql API для получения данных.
import 'package:flutter/material.dart';
import 'services.dart';
import 'package:http/http.dart' as http;
import 'Employee.dart';
import 'DataTableDemo.dart';
class FavoritesPage extends StatefulWidget {
@override
FavoritesPageState createState() => FavoritesPageState();
}
class FavoritesPageState extends State<FavoritesPage>{
@override
Widget build(BuildContext context) {
return new MaterialApp(
theme: new ThemeData(
primarySwatch: Colors.deepOrange,
),
home: new Scaffold(
appBar: new AppBar(title: const Text('MySQL Images Text')),
body: new Center(
//FutureBuilder is a widget that builds itself based on the latest snapshot
// of interaction with a Future.
child: new FutureBuilder<List<Employee>>(
future: Services.getEmployees(),
//we pass a BuildContext and an AsyncSnapshot object which is an
//Immutable representation of the most recent interaction with
//an asynchronous computation.
builder: (context, snapshot) {
if (snapshot.hasData) {
List<Employee> _employee = snapshot.data;
return CustomListView(_employee);
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
}
//return a circular progress indicator.
return new CircularProgressIndicator();
},
),
),
),
);
}
}
class CustomListView extends StatefulWidget {
List<Employee> _employee;
CustomListView(this._employee);
CustomListViewState createState() => CustomListViewState();
}
class CustomListViewState extends State<CustomListView>{
List<Employee> _employee;
Widget build(context) {
return ListView.builder(
itemCount: _employee.length,
itemBuilder: (context, int currentIndex) {
return createViewItem(_employee[currentIndex], context);
},
);
}
@override
void initState() {
_employee = [];
_getEmployees();
}
Widget createViewItem(Employee _employee, BuildContext context) {
return new Card(
child: new Column(
children: <Widget>[
new ListTile(
leading: new Image.asset(_employee.path, fit: BoxFit.cover),
title: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
_employee.firstName,
style: new TextStyle(
fontSize: 19.0,
fontWeight: FontWeight.bold,
),
),
Row(
children: <Widget>[
FlatButton(
child: Text('-', style: TextStyle(fontSize: 28.0)),
onPressed: () {},
),
Text(_employee.id),
FlatButton(
child: Text(
'+',
style: TextStyle(fontSize: 28.0),
),
onPressed: () {},
),
],
)
],
),
subtitle: new Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
IconButton(
onPressed: () {
_deleteEmployee(_employee);
},
icon: Icon(Icons.delete),
),
new Text('\$' + _employee.price,
style: new TextStyle(
fontSize: 15.0, fontWeight: FontWeight.normal)),
]),
//trailing: ,
onTap: () {},
)
],
));
}
}
_deleteEmployee(Employee employee) {
Services.deleteEmployee(employee.id).then((result) {
if ('success' == result) {
_getEmployees(); // Refresh after delete...
}
});
}
_getEmployees() {
Services.getEmployees().then((employees) {
print("Length ${employees.length}");
});
}