mirror of
https://bitbucket.org/FransoletThomas/tablet-app.git
synced 2025-12-06 00:21:19 +00:00
First try - get sections
This commit is contained in:
parent
d0724b0099
commit
fb202d252c
@ -1,5 +1,3 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@ -11,6 +9,7 @@ import 'package:tablet_app/Components/loading.dart';
|
||||
import 'package:tablet_app/Components/webView.dart';
|
||||
import 'package:tablet_app/Models/map-marker.dart';
|
||||
import 'package:tablet_app/Models/section.dart';
|
||||
import 'package:tablet_app/Models/tabletContext.dart';
|
||||
import 'package:tablet_app/app_context.dart';
|
||||
import 'package:tablet_app/constants.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
@ -25,7 +24,7 @@ class MainViewWidget extends StatefulWidget {
|
||||
|
||||
class _MainViewWidget extends State<MainViewWidget> {
|
||||
Size sizeScreen = new Size(1080.0, 1920.0); // Tablet resolution
|
||||
Section sectionSelected;
|
||||
SectionDTO sectionSelected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -35,8 +34,8 @@ class _MainViewWidget extends State<MainViewWidget> {
|
||||
|
||||
if(sectionSelected != null) {
|
||||
var elementToShow;
|
||||
switch (sectionSelected.category) {
|
||||
case 0 : // MAP
|
||||
switch (sectionSelected.type) {
|
||||
case SectionType.map : // MAP
|
||||
elementToShow = ChangeNotifierProvider<MapContext>(
|
||||
create: (_) =>
|
||||
MapContext(new MapMarker(
|
||||
@ -51,10 +50,10 @@ class _MainViewWidget extends State<MainViewWidget> {
|
||||
: CircularProgressIndicator()),*/
|
||||
);
|
||||
break;
|
||||
case 1 : // WEB
|
||||
case SectionType.web : // WEB
|
||||
elementToShow = WebViewWidget(url: 'Test');
|
||||
break;
|
||||
case 2 :
|
||||
case SectionType.slider :
|
||||
elementToShow = Padding(
|
||||
padding: const EdgeInsets.all(15.0),
|
||||
child: Text('Hellow in')
|
||||
@ -96,7 +95,7 @@ class _MainViewWidget extends State<MainViewWidget> {
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: AutoSizeText(
|
||||
sectionSelected.title,
|
||||
sectionSelected.title.firstWhere((translation) => translation.language == appContext.getContext().language).value,
|
||||
style: new TextStyle(fontSize: 25),
|
||||
maxLines: 1,
|
||||
),
|
||||
@ -106,7 +105,7 @@ class _MainViewWidget extends State<MainViewWidget> {
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: AutoSizeText(
|
||||
sectionSelected.description,
|
||||
sectionSelected.description.firstWhere((translation) => translation.language == appContext.getContext().language).value,
|
||||
style: new TextStyle(fontSize: 20),
|
||||
maxLines: 2,
|
||||
),
|
||||
@ -183,14 +182,18 @@ class _MainViewWidget extends State<MainViewWidget> {
|
||||
height: size.height * 0.9,
|
||||
width: size.width * 0.9,
|
||||
child: FutureBuilder(
|
||||
future: getSections(),
|
||||
future: getSections(appContext),
|
||||
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||
print('helloo test');
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
if (snapshot.data == null) {
|
||||
return Text("NO CONFIGURATION");
|
||||
}
|
||||
else {
|
||||
return GridView.builder(
|
||||
shrinkWrap: true,
|
||||
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4),
|
||||
itemCount: snapshot.data.length,
|
||||
itemCount: snapshot.data?.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return // User Picture
|
||||
InkWell(
|
||||
@ -212,7 +215,7 @@ class _MainViewWidget extends State<MainViewWidget> {
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: AutoSizeText(
|
||||
snapshot.data[index].title,
|
||||
snapshot.data[index].title.firstWhere((translation) => translation.language == appContext.getContext().language).value,
|
||||
style: new TextStyle(fontSize: 25),
|
||||
maxLines: 1,
|
||||
),
|
||||
@ -220,7 +223,7 @@ class _MainViewWidget extends State<MainViewWidget> {
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: AutoSizeText(
|
||||
snapshot.data[index].description,
|
||||
snapshot.data[index].description.firstWhere((translation) => translation.language == appContext.getContext().language).value,
|
||||
style: new TextStyle(fontSize: 18, fontFamily: ""),
|
||||
maxLines: 1,
|
||||
),
|
||||
@ -233,6 +236,7 @@ class _MainViewWidget extends State<MainViewWidget> {
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
} else if (snapshot.connectionState == ConnectionState.none) {
|
||||
return Text("No data");
|
||||
} else {
|
||||
@ -252,9 +256,22 @@ class _MainViewWidget extends State<MainViewWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Section>> getSections() async {
|
||||
Future<List<SectionDTO>> getSections(dynamic appContext) async {
|
||||
TabletAppContext tabletAppContext = await appContext.getContext();
|
||||
|
||||
print('in future');
|
||||
// TODO if null ask user to select a config (first use)
|
||||
if (tabletAppContext.configuration == null) {
|
||||
print("config is null");
|
||||
tabletAppContext.configuration = await tabletAppContext.clientAPI.configurationApi.configurationGetDetail("60b1257a2939c9163c3f0921");
|
||||
print("Set context.. if no config");
|
||||
appContext.setContext(tabletAppContext);
|
||||
}
|
||||
|
||||
print(tabletAppContext.toString());
|
||||
List<SectionDTO> sections = await tabletAppContext.clientAPI.sectionApi.sectionGetFromConfiguration(tabletAppContext.configuration.id);
|
||||
print(sections);
|
||||
return sections;
|
||||
/*print('in future');
|
||||
final response = await http.get('https://jsonplaceholder.typicode.com/posts/1');
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
@ -271,12 +288,12 @@ class _MainViewWidget extends State<MainViewWidget> {
|
||||
} else {
|
||||
// If that call was not successful, throw an error.
|
||||
throw Exception('Failed to load post');
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
boxDecoration(Section section) {
|
||||
boxDecoration(SectionDTO section) {
|
||||
return BoxDecoration(
|
||||
color: kBackgroundLight,
|
||||
shape: BoxShape.rectangle,
|
||||
@ -285,7 +302,7 @@ boxDecoration(Section section) {
|
||||
fit: BoxFit.cover,
|
||||
colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.6), BlendMode.dstATop),
|
||||
image: new NetworkImage(
|
||||
section.image,
|
||||
section.imageSource,
|
||||
),
|
||||
),
|
||||
boxShadow: [
|
||||
|
||||
@ -36,16 +36,20 @@ class MyApp extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
TabletAppContext tabletAppContext;
|
||||
Client clientAPI = new Client();
|
||||
|
||||
TabletAppContext tabletAppContext;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
if (widget.tabletAppContext == null) {
|
||||
tabletAppContext = new TabletAppContext();
|
||||
// store user info locally
|
||||
tabletAppContext.clientAPI = clientAPI;
|
||||
print(tabletAppContext);
|
||||
tabletAppContext.configuration = new ConfigurationDTO(id: "60b1257a2939c9163c3f0921");
|
||||
tabletAppContext.language = "FR";
|
||||
|
||||
//appContext.setContext(tabletAppContext);
|
||||
|
||||
/*List<SectionDTO> sections = await clientAPI.sectionApi.sectionGetFromConfiguration("60b1257a2939c9163c3f0921");
|
||||
print("number of sections " + sections.length.toString());
|
||||
@ -62,7 +66,7 @@ class _MyAppState extends State<MyApp> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChangeNotifierProvider<AppContext>(
|
||||
create: (_) => AppContext(widget.tabletAppContext),
|
||||
create: (_) => AppContext(tabletAppContext),
|
||||
child: MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
title: 'Tablet App Demo',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user