Amélioration page ship
This commit is contained in:
@@ -58,15 +58,22 @@ class Inventory {
|
||||
class Cargo {
|
||||
int? capacity;
|
||||
int? units;
|
||||
//List<Inventory>? inventory;
|
||||
List<Inventory>? inventory;
|
||||
|
||||
Cargo({this.capacity, this.units});//, this.inventory});
|
||||
Cargo({this.capacity, this.units, this.inventory});
|
||||
|
||||
factory Cargo.fromJson(Map<String, dynamic> json) {
|
||||
var inventoryList = json['inventory'] as List<dynamic>?;
|
||||
List<Inventory>? parsedInventoryList;
|
||||
if (inventoryList != null) {
|
||||
parsedInventoryList = inventoryList
|
||||
.map((item) => Inventory.fromJson(item))
|
||||
.toList();
|
||||
}
|
||||
return Cargo(
|
||||
capacity: json['capacity'],
|
||||
units: json['units'],
|
||||
//inventory: json.decode(json['inventory']),
|
||||
inventory: parsedInventoryList,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,91 +71,91 @@ class _HomePageState extends State<HomePage> {
|
||||
builder: (BuildContext context, AsyncSnapshot<List<ShipModel>> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
List<ShipModel> ships = snapshot.data!;
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
width: MediaQuery.of(context).size.width, // Utiliser la largeur de l'écran
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Table(
|
||||
defaultColumnWidth: IntrinsicColumnWidth(),
|
||||
children: ships.map((ship) {
|
||||
return TableRow(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ShipPage(ship: ship),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('${ship.symbol ?? 'N/A'}'),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ShipPage(ship: ship),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('${ship.nav?.status ?? 'N/A'}'),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ShipPage(ship: ship),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Fuel: ${ship.fuel?.current ?? 'N/A'} / ${ship.fuel?.capacity ?? 'N/A'}'),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ShipPage(ship: ship),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Cargo: ${ship.cargo?.units ?? 'N/A'} / ${ship.cargo?.capacity ?? 'N/A'}'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
width: MediaQuery.of(context).size.width, // Utiliser la largeur de l'écran
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Table(
|
||||
defaultColumnWidth: IntrinsicColumnWidth(),
|
||||
children: ships.map((ship) {
|
||||
return TableRow(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ShipPage(ship: ship),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('${ship.symbol ?? 'N/A'}'),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ShipPage(ship: ship),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('${ship.nav?.status ?? 'N/A'}'),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ShipPage(ship: ship),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Fuel: ${ship.fuel?.current ?? 'N/A'} / ${ship.fuel?.capacity ?? 'N/A'}'),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ShipPage(ship: ship),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Cargo: ${ship.cargo?.units ?? 'N/A'} / ${ship.cargo?.capacity ?? 'N/A'}'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text('Error: ${snapshot.error}');
|
||||
} else {
|
||||
|
||||
@@ -2,19 +2,139 @@ import 'package:flutter/material.dart';
|
||||
import 'package:space_traders/models/ship_model.dart';
|
||||
|
||||
class ShipPage extends StatelessWidget {
|
||||
final ShipModel ship;
|
||||
final ShipModel ship;
|
||||
|
||||
ShipPage({required this.ship});
|
||||
ShipPage({required this.ship});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Ship Details'),
|
||||
),
|
||||
body: Center(
|
||||
child: Text('Ship Symbol: ${ship.symbol}'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
ElevatedButton buildActionButton(String status) {
|
||||
String buttonText = '';
|
||||
VoidCallback? buttonAction;
|
||||
|
||||
if (status == 'IN_ORBIT') {
|
||||
buttonText = 'Dock';
|
||||
buttonAction = () {
|
||||
// Action 1
|
||||
print('Action 1');
|
||||
};
|
||||
} else if (status == 'Status2') {
|
||||
buttonText = 'Action 2';
|
||||
buttonAction = () {
|
||||
// Action 2
|
||||
print('Action 2');
|
||||
};
|
||||
} else {
|
||||
buttonText = 'Default Action';
|
||||
buttonAction = () {
|
||||
// Default Action
|
||||
print('Default Action');
|
||||
};
|
||||
}
|
||||
|
||||
return ElevatedButton(
|
||||
onPressed: buttonAction,
|
||||
child: Text(buttonText),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Ship Details'),
|
||||
),
|
||||
body: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[300],
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Card(
|
||||
color: Colors.white,
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Name: ${ship.symbol}',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text('${ship.nav?.status ?? 'N/A'}'),
|
||||
SizedBox(height: 32),
|
||||
SizedBox(width: 32),
|
||||
buildActionButton(ship.nav?.status ?? ''),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text('Fuel: ${ship.fuel?.current ?? 'N/A'} / ${ship.fuel?.capacity ?? 'N/A'}'),
|
||||
SizedBox(height: 32),
|
||||
SizedBox(width: 32),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
},
|
||||
child: Text('Refuel'),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Column(
|
||||
children:[
|
||||
Text('${ship.nav?.waypointSymbol ?? 'N/A'}'),
|
||||
Text('Asteroid Field'),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 32),
|
||||
SizedBox(width: 32),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
},
|
||||
child: Text('Select Destination'),
|
||||
),
|
||||
SizedBox(width: 32),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
},
|
||||
child: Text('View System'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Card(
|
||||
color: Colors.white,
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Cargo: ${ship.cargo?.units ?? 'N/A'} / ${ship.cargo?.capacity ?? 'N/A'}',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ class ShipProvider {
|
||||
);
|
||||
|
||||
final decodedData = json.decode(utf8.decode(resp.bodyBytes));
|
||||
//final fleet = FleetModel.fromJson(decodedData['data']);
|
||||
final List<ShipModel> fleet = [];
|
||||
final List<dynamic> data = decodedData['data'];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user