Skip to content

Commit

Permalink
[GetHistory] start loading getHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannBrglt committed Feb 9, 2024
1 parent 160743e commit f327339
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 131 deletions.
10 changes: 0 additions & 10 deletions client_flutter/lib/core/repository/kara_repo.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:convert';

import 'package:kar_assistant/core/models/kara_response.dart';
import 'package:kar_assistant/core/repository/kara_repository.dart';
import 'package:kar_assistant/services/http_repo.dart';
Expand All @@ -18,12 +16,4 @@ class KaraRepo implements KaraRepository {
rethrow;
}
}

// @override
// Future getHistory(
// Map<String, String> data,
// ) {
// print(data);
// return object =
// }
}
1 change: 0 additions & 1 deletion client_flutter/lib/core/repository/kara_repository.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
abstract class KaraRepository {
Future heyKara(Map<String, String> data);
// Future getHistory(Map<String, String> data);
}
19 changes: 19 additions & 0 deletions client_flutter/lib/core/repository/user_repo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:kar_assistant/core/repository/user_repository.dart';
import 'package:kar_assistant/services/http_repo.dart';

class UserRepo extends UserRepository {
@override
Future<Map<String, dynamic>> getHistory() async {
try {
print('get History');
Map<String, dynamic> data =
{}; // empty because juste need DATE and date is filled inside ParamsSecure
Map<String, dynamic> value =
await HttpRepo().getRequestParamsSecure("api/user/history", data);
print('value: ${value}');
return value;
} catch (err) {
rethrow;
}
}
}
3 changes: 3 additions & 0 deletions client_flutter/lib/core/repository/user_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
abstract class UserRepository {
Future<Map<String, dynamic>> getHistory();
}
1 change: 0 additions & 1 deletion client_flutter/lib/core/widgets/work_in_progress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ class WorkInProgress extends StatelessWidget {
],
),
);
;
}
}
105 changes: 1 addition & 104 deletions client_flutter/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,115 +15,12 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'kar_assistant',
title: 'KarAssistant',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a blue toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const HomePage(),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});

// 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<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:kar_assistant/core/widgets/work_in_progress.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';

class ActionsPage extends StatefulWidget {
const ActionsPage({super.key});
Expand All @@ -12,6 +11,6 @@ class ActionsPage extends StatefulWidget {
class _ActionsPageState extends State<ActionsPage> {
@override
Widget build(BuildContext context) {
return WorkInProgress();
return const WorkInProgress();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:kar_assistant/core/models/conversation/message_conversation.dart';
import 'package:kar_assistant/core/models/kara_response.dart';
import 'package:kar_assistant/core/repository/kara_repo.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:kar_assistant/core/repository/user_repo.dart';

class UserController {
Map<String, dynamic>? currentHistory;
Future<void> initInfoUser() async {
// await Future.wait([loadHistory()]);
}

Future<void> loadHistory() async {
Map<String, dynamic> result = await UserRepo().getHistory();
currentHistory = result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ class DiscordDialogConfigure extends StatelessWidget {
actionsAlignment: MainAxisAlignment.start,
actions: [
ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Annuler'))
onPressed: () {
Navigator.pop(context);
},
child: const Text('Annuler'),
),
],
);
}
Expand Down
8 changes: 7 additions & 1 deletion client_flutter/lib/screens/home_page/view/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:animations/animations.dart';
import 'package:kar_assistant/screens/actions_page/view/actions_page.dart';
import 'package:kar_assistant/screens/history_page/view/history_page.dart';
import 'package:kar_assistant/screens/home_page/controller/kara_controller.dart';
import 'package:kar_assistant/screens/home_page/controller/user_controller.dart';
import 'package:kar_assistant/screens/home_page/view/kara_talking.dart';
import 'package:kar_assistant/screens/home_page/view/my_profil.dart';
import 'package:kar_assistant/services/utils_controller.dart';
Expand All @@ -20,11 +21,16 @@ class _HomePageState extends State<HomePage> with RestorationMixin {
final RestorableInt _currentIndexPage = RestorableInt(0);
final PageController controllerPage = PageController(initialPage: 0);
late KaraController karaController;
late UserController userController;

@override
void initState() {
print('restart App');
karaController = KaraController();
UtilsController().verifTokenExistStorage();
userController = UserController();
UtilsController().verifTokenExistStorage().then((value) {
userController.initInfoUser();
});
super.initState();
}

Expand Down
92 changes: 91 additions & 1 deletion client_flutter/lib/screens/options_page/view/options_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'package:flutter/material.dart';
import 'package:kar_assistant/core/widgets/work_in_progress.dart';
import 'package:kar_assistant/main.dart';
import 'package:kar_assistant/services/utils_controller.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';

class OptionsPage extends StatelessWidget {
const OptionsPage({super.key});
Expand All @@ -14,7 +17,94 @@ class OptionsPage extends StatelessWidget {
),
backgroundColor: Theme.of(context).colorScheme.primary,
),
body: WorkInProgress(),
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Expanded(child: WorkInProgress()),
Expanded(
child: Column(
children: [
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith(
(Set<MaterialState> states) {
if (states.contains(MaterialState.pressed)) {
return Colors.red;
} else {
return Colors.transparent;
}
},
),
),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text(
'Attention',
),
content: const Text(
'Vous allez suprimmer votre compte et en créé un nouveau, êtes vous sur ?',
style: TextStyle(color: Colors.red),
),
actions: [
ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Annuler'),
),
ElevatedButton(
onPressed: () async {
UtilsController().removeToken().then((value) {
Navigator.of(context)
.popUntil((route) => false);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const MyApp(),
),
);
// final SnackBar snackBar = SnackBar(
// content: const Row(
// children: [
// Icon(MdiIcons.check),
// Text(
// 'Compte supprimer',
// style: TextStyle(color: Colors.green),
// ),
// ],
// ),
// duration: const Duration(seconds: 4),
// backgroundColor: Colors.transparent,
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(5),
// ),
// behavior: SnackBarBehavior.floating,
// width: 200,
// );
// snackBarKey.currentState
// ?.showSnackBar(SnackBar(
// content: Text('test'),
// duration: Duration(seconds: 4),
// ));
});
},
child: const Text('Confirmez'),
),
],
);
},
);
},
child: const Text('Supprimer le compte'),
),
],
),
),
],
),
);
}
}
8 changes: 5 additions & 3 deletions client_flutter/lib/services/http_repo.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:kar_assistant/core/globals.dart' as globals;
import 'package:http/http.dart' as http;
import 'package:kar_assistant/services/http_repository.dart';
Expand Down Expand Up @@ -99,7 +101,6 @@ class HttpRepo implements HttpRepository {
(error, stackTrace) => http.Response(responseOtherError, 503),
);
if (response.statusCode < 200 || response.statusCode > 299) {
inspect(response);
final error = json.decode(response.body);
throw error['message'];
}
Expand Down Expand Up @@ -128,6 +129,8 @@ class HttpRepo implements HttpRepository {
.onError(
(error, stackTrace) => http.Response(responseOtherError, 503),
);
print(response.statusCode);
print(response.body);
if (response.statusCode < 200 || response.statusCode > 299) {
if (response.statusCode == 404 && secondTry != true) {
print('recreateUser');
Expand All @@ -136,8 +139,7 @@ class HttpRepo implements HttpRepository {
return await HttpRepo()
.getRequestParamsSecure(url, data, secondTry: true);
}
final error = json.decode(response.body);
throw error['message'];
throw response.body;
}

var parsedResponse = jsonDecode(response.body);
Expand Down
Loading

0 comments on commit f327339

Please sign in to comment.