aboutsummaryrefslogtreecommitdiff
path: root/lib/views/week_view.dart
blob: de6ebcf1acee560a2b30b560ed35434d8fb3f539 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import 'package:flutter/material.dart';

import 'package:kulinar_app/widgets/error_widgets.dart';
import 'package:kulinar_app/widgets/custom_drawer_widget.dart';
import 'package:kulinar_app/models/data/settings_data_class.dart';

import 'package:http/http.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class WeekView extends StatefulWidget {
  const WeekView({Key? key}) : super(key: key);

  @override
  WeekViewState createState() => WeekViewState();
}

class WeekViewState extends State<WeekView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(AppLocalizations.of(context)!.category5)),
      drawer: const CustomDrawer(initialIndex: 2),
      body: FutureBuilder(
        future: _getWeeklyRecipes(),
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          if (snapshot.connectionState != ConnectionState.done) return const LinearProgressIndicator();
          if (snapshot.hasError || !snapshot.hasData) return NetworkContentError(refreshCallback: _retry);

          return RefreshIndicator(
            onRefresh: () async {
              setState(() {});
            },
            child: ListView(
              children: const [
                Text("Not implemented"), // TODO: Not implemented
              ],
            ),
          );
        },
      ),
    );
  }

  Future<Response?> _getWeeklyRecipes() async {
    Map<String, String> _headers = {"Content-Type": "application/json; charset=UTF-8"};

    try {
      return await Future.delayed(const Duration(milliseconds: 500), () {
        debugPrint("${SettingsData.settings['serverURL']}");
        return get(Uri.https(SettingsData.settings["serverURL"]!, "/weekly"), headers: _headers);
      });
    } catch (e) {
      debugPrint("$e");
      return null;
    }
  }

  Future<void> _retry() async {
    await Future.delayed(const Duration(milliseconds: 300));

    setState(() {});
  }
}