mirror of
https://bitbucket.org/FransoletThomas/tablet-app.git
synced 2025-12-06 00:21:19 +00:00
242 lines
10 KiB
Dart
242 lines
10 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:tablet_app/Components/Map/map_context.dart';
|
|
import 'package:tablet_app/Components/Map/map_view.dart';
|
|
import 'package:tablet_app/Models/map-marker.dart';
|
|
import 'package:tablet_app/Models/section.dart';
|
|
import 'package:tablet_app/constants.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
class MainViewWidget extends StatefulWidget {
|
|
MainViewWidget();
|
|
|
|
@override
|
|
_MainViewWidget createState() => _MainViewWidget();
|
|
}
|
|
|
|
class _MainViewWidget extends State<MainViewWidget> {
|
|
Size sizeScreen = new Size(1080.0, 1920.0); // Tablet resolution
|
|
Section sectionSelected;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
SystemChrome.setEnabledSystemUIOverlays([]);
|
|
Size size = MediaQuery.of(context).size;
|
|
|
|
if(sectionSelected != null) {
|
|
var elementToShow;
|
|
switch (sectionSelected.category) {
|
|
case 0 : // MAP
|
|
elementToShow = ChangeNotifierProvider<MapContext>(
|
|
create: (_) =>
|
|
MapContext(new MapMarker(
|
|
latitude: null,
|
|
longitude: null,
|
|
title: '',
|
|
description: '',
|
|
text: '')),
|
|
child: MapViewWidget() /*FutureBuilder(
|
|
future: _url,
|
|
builder: (BuildContext context, AsyncSnapshot snapshot) => snapshot.hasData
|
|
? WebViewWidget(url: snapshot.data,)
|
|
: CircularProgressIndicator()),*/
|
|
);
|
|
break;
|
|
case 1 : // WEB
|
|
break;
|
|
case 0 :
|
|
break;
|
|
}
|
|
return Scaffold(
|
|
body: Column(
|
|
children: [
|
|
Container(
|
|
width: size.width,
|
|
height: size.height * 0.15,
|
|
child: Row(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 15.0, top: 10.0),
|
|
child: Container(
|
|
width: 150,
|
|
height: 150,
|
|
decoration: boxDecoration(sectionSelected),
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: 25,
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: Text(sectionSelected.title, style: new TextStyle(fontSize: 35))
|
|
),
|
|
Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: Text(sectionSelected.description, style: new TextStyle(fontSize: 25)))
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 15.0, right: 15.0, top: 10.0),
|
|
child: Container(
|
|
width: size.width,
|
|
height: size.height * 0.822,
|
|
decoration: BoxDecoration(
|
|
color: kBackgroundLight,
|
|
shape: BoxShape.rectangle,
|
|
borderRadius: BorderRadius.circular(30.0),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: kBackgroundSecondGrey,
|
|
spreadRadius: 0.5,
|
|
blurRadius: 5,
|
|
offset: Offset(0, 1.5), // changes position of shadow
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.startFloat,
|
|
floatingActionButton: Container(
|
|
height: 125.0,
|
|
width: 125.0,
|
|
child: FittedBox(
|
|
child: FloatingActionButton.extended(
|
|
onPressed: () {
|
|
setState(() {
|
|
sectionSelected = null;
|
|
});
|
|
},
|
|
icon: Icon(Icons.arrow_back),
|
|
label: Text("Menu"),
|
|
),
|
|
),
|
|
),
|
|
|
|
);
|
|
} else {
|
|
return Scaffold(
|
|
body: Container(
|
|
height: size.height,
|
|
width: size.width,
|
|
color: kBackgroundGrey,
|
|
child: Center(
|
|
child: Container(
|
|
height: size.height * 0.85,
|
|
width: size.width * 0.9,
|
|
child: FutureBuilder(
|
|
future: getSections(),
|
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
|
print('helloo test');
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
return GridView.builder(
|
|
shrinkWrap: true,
|
|
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4),
|
|
itemCount: snapshot.data.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return // User Picture
|
|
InkWell(
|
|
onTap: () {
|
|
setState(() {
|
|
sectionSelected = snapshot.data[index];
|
|
});
|
|
},
|
|
child: Container(
|
|
decoration: boxDecoration(snapshot.data[index]),
|
|
padding: const EdgeInsets.all(20),
|
|
margin: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
|
child: Align(
|
|
alignment: Alignment.bottomRight,
|
|
child: FractionallySizedBox(
|
|
heightFactor: 0.35,
|
|
child: Column(
|
|
children: [
|
|
Align(
|
|
alignment: Alignment.centerRight,
|
|
child: Text(snapshot.data[index].title, style: new TextStyle(fontSize: 35))),
|
|
Align(
|
|
alignment: Alignment.centerRight,
|
|
child: Text(snapshot.data[index].description, style: new TextStyle(fontSize: 25, fontFamily: ""))
|
|
),
|
|
],
|
|
)
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
);
|
|
} else if (snapshot.connectionState == ConnectionState.none) {
|
|
return Text("No data");
|
|
} else {
|
|
return Center(child: Container(height: size.height * 0.2, child: Text('LOADING TODO FRAISE')));
|
|
}
|
|
}
|
|
),
|
|
),
|
|
),
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<List<Section>> getSections() async {
|
|
|
|
print('in future');
|
|
final response = await http.get('https://jsonplaceholder.typicode.com/posts/1');
|
|
|
|
if (response.statusCode == 200) {
|
|
// If the call to the server was successful, parse the JSON.
|
|
return [
|
|
new Section(id: 0, title: "TEST Map", description: "Ceci est l'essai d'une carte", image: "https://www.novo-monde.com/app/uploads/2017/11/novo-map-banner-3.jpg", category: 0),
|
|
new Section(id: 0, title: "TEST Site web", description: "Ceci est l'essai d'un site web", image: "https://static.wixstatic.com/media/38e2f4_4c1714f38942446e99c1e736726e4465~mv2.jpg/v1/fill/w_892,h_564,al_c,q_85,usm_0.66_1.00_0.01/38e2f4_4c1714f38942446e99c1e736726e4465~mv2.webp", category: 1),
|
|
new Section(id: 0, title: "TEST 2", description: "fsfsdf", image: "https://static.wixstatic.com/media/38e2f4_4c1714f38942446e99c1e736726e4465~mv2.jpg/v1/fill/w_892,h_564,al_c,q_85,usm_0.66_1.00_0.01/38e2f4_4c1714f38942446e99c1e736726e4465~mv2.webp", category: 0),
|
|
new Section(id: 0, title: "TEST 3", description: "fsfsdf", image: "https://static.wixstatic.com/media/38e2f4_4c1714f38942446e99c1e736726e4465~mv2.jpg/v1/fill/w_892,h_564,al_c,q_85,usm_0.66_1.00_0.01/38e2f4_4c1714f38942446e99c1e736726e4465~mv2.webp", category: 0),
|
|
new Section(id: 0, title: "TEST 4", description: "fsfsdf", image: "https://static.wixstatic.com/media/38e2f4_4c1714f38942446e99c1e736726e4465~mv2.jpg/v1/fill/w_892,h_564,al_c,q_85,usm_0.66_1.00_0.01/38e2f4_4c1714f38942446e99c1e736726e4465~mv2.webp", category: 0),
|
|
new Section(id: 0, title: "TEST 5", description: "fsfsdf", image: "https://static.wixstatic.com/media/38e2f4_4c1714f38942446e99c1e736726e4465~mv2.jpg/v1/fill/w_892,h_564,al_c,q_85,usm_0.66_1.00_0.01/38e2f4_4c1714f38942446e99c1e736726e4465~mv2.webp", category: 0),
|
|
new Section(id: 0, title: "TEST 6", description: "fsfsdf", image: "https://static.wixstatic.com/media/38e2f4_4c1714f38942446e99c1e736726e4465~mv2.jpg/v1/fill/w_892,h_564,al_c,q_85,usm_0.66_1.00_0.01/38e2f4_4c1714f38942446e99c1e736726e4465~mv2.webp", category: 0),
|
|
];
|
|
} else {
|
|
// If that call was not successful, throw an error.
|
|
throw Exception('Failed to load post');
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
boxDecoration(Section section) {
|
|
return BoxDecoration(
|
|
color: kBackgroundLight,
|
|
shape: BoxShape.rectangle,
|
|
borderRadius: BorderRadius.circular(30.0),
|
|
image: new DecorationImage(
|
|
fit: BoxFit.cover,
|
|
colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.6), BlendMode.dstATop),
|
|
image: new NetworkImage(
|
|
section.image,
|
|
),
|
|
),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: kBackgroundSecondGrey,
|
|
spreadRadius: 0.5,
|
|
blurRadius: 5,
|
|
offset: Offset(0, 1.5), // changes position of shadow
|
|
),
|
|
],
|
|
);
|
|
} |