135 lines
4.8 KiB
Dart

import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:manager_api/api.dart';
import 'package:mymuseum_visitapp/Screens/Scanner/scanner.dart';
import 'package:mymuseum_visitapp/client.dart';
import 'package:mymuseum_visitapp/constants.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key, required this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
List<ConfigurationDTO> configurations = [ConfigurationDTO(label: "Test 0", isOffline: false), ConfigurationDTO(label: "Test 1", isOffline: true), ConfigurationDTO(label: "Test 2", isOffline: true)];
//List<dynamic> configurations = [];
void _incrementCounter() {
setState(() {
//_counter++;
});
}
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Container(
width: size.width,
height: size.height,
child: GridView.builder(
shrinkWrap: true,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 1),
itemCount: configurations.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
onTap: () {
setState(() {
//sectionSelected = snapshot.data[index];
print("config selected");
getConfiguration();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return ScannerPage(title: "test");
},
),
);
});
},
child: Container(
decoration: boxDecoration(configurations[index], false),
padding: const EdgeInsets.all(25),
margin: const EdgeInsets.symmetric(vertical: 25, horizontal: 25),
child: Align(
alignment: Alignment.bottomRight,
child: FractionallySizedBox(
heightFactor: 0.4,
child: Column(
children: [
Align(
alignment: Alignment.centerRight,
child: AutoSizeText(
configurations[index].label!,
style: const TextStyle(fontSize: kMenuTitleDetailSize),
maxLines: 1,
),
),
Align(
alignment: Alignment.centerRight,
child: AutoSizeText(
configurations[index].isOffline.toString(),
style: const TextStyle(fontSize: kMenuDescriptionDetailSize, fontFamily: ""),
maxLines: 1,
),
),
],
)
),
),
),
);
}
),
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
Future<List<ConfigurationDTO>?> getConfiguration() async {
try {
var client = new Client("http://192.168.31.140:8089");
List<ConfigurationDTO>? configurations = await client.configurationApi!.configurationGet();
print(configurations);
return configurations;
} catch (e) {
print(e);
print("IN CATCH");
}
}
}
boxDecoration(ConfigurationDTO configuration, bool isSelected) { // TODO to change
return BoxDecoration(
color: Colors.cyan,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(30.0),
boxShadow: const [
BoxShadow(
color: kBackgroundSecondGrey,
spreadRadius: 0.5,
blurRadius: 5,
offset: Offset(0, 1.5), // changes position of shadow
),
],
);
}