150 lines
5.0 KiB
Dart
150 lines
5.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:insparkspokalen_ui/feed/usersHomeScreen/info_smallpage.dart';
|
|
import 'package:insparkspokalen_ui/models/teamModel.dart';
|
|
import 'package:insparkspokalen_ui/services/image_service.dart';
|
|
import 'package:insparkspokalen_ui/services/teamService.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'dart:io';
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
class MainPageForInfo extends StatefulWidget {
|
|
const MainPageForInfo({super.key});
|
|
|
|
@override
|
|
State<MainPageForInfo> createState() => MainPageForInfoState();
|
|
}
|
|
|
|
class MainPageForInfoState extends State<MainPageForInfo> {
|
|
late List<TeamModel> teamItems = [];
|
|
late ImageService imageService;
|
|
late final TeamService teamService;
|
|
final TextEditingController textController = TextEditingController();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
teamService = Provider.of<TeamService>(context, listen: false);
|
|
imageService = Provider.of<ImageService>(context, listen: false);
|
|
|
|
_loadItems();
|
|
}
|
|
|
|
Future<void> _loadItems() async {
|
|
final items = await teamService.showTeams();
|
|
setState(() {
|
|
teamItems = items;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: const Color(0xFF2E2E2E),
|
|
body: SafeArea(
|
|
child:
|
|
teamItems.isEmpty
|
|
? const Center(child: Text('Inga grupper hittades'))
|
|
: ListView.builder(
|
|
itemCount: teamItems.length,
|
|
itemBuilder: (context, index) {
|
|
final team = teamItems[index];
|
|
return InfoSmallpage(group: team);
|
|
},
|
|
),
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
backgroundColor: Colors.white,
|
|
onPressed: () {
|
|
showAddPostDialog(context);
|
|
},
|
|
child: const Icon(Icons.add, color: Colors.black),
|
|
),
|
|
);
|
|
}
|
|
|
|
void showAddPostDialog(BuildContext context) {
|
|
File? selectedImage;
|
|
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
return StatefulBuilder(
|
|
builder: (context, setState) {
|
|
return AlertDialog(
|
|
backgroundColor: Colors.white,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
title: const Text("Nytt inlägg"),
|
|
content: SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextField(
|
|
controller: textController,
|
|
decoration: const InputDecoration(
|
|
hintText: "Skriv din information här",
|
|
),
|
|
maxLines: 3,
|
|
),
|
|
const SizedBox(height: 10),
|
|
selectedImage != null
|
|
? Image.file(selectedImage!, height: 150)
|
|
: const Text("Ingen bild vald"),
|
|
TextButton.icon(
|
|
onPressed: () async {
|
|
final pickedFile = await ImagePicker().pickImage(
|
|
source: ImageSource.gallery,
|
|
);
|
|
if (pickedFile != null) {
|
|
imageService.upload(pickedFile);
|
|
setState(() {
|
|
selectedImage = File(pickedFile.path);
|
|
});
|
|
}
|
|
},
|
|
icon: const Icon(Icons.image),
|
|
label: const Text("Välj bild"),
|
|
),
|
|
TextButton.icon(
|
|
onPressed: () async {
|
|
final pickedFile = await ImagePicker().pickImage(
|
|
source: ImageSource.camera,
|
|
);
|
|
if (pickedFile != null) {
|
|
imageService.upload(pickedFile);
|
|
setState(() {
|
|
selectedImage = File(pickedFile.path);
|
|
});
|
|
}
|
|
},
|
|
icon: const Icon(Icons.camera_alt),
|
|
label: const Text("Ta bild"),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text("Avbryt"),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
// Här sparar du eller skickar datan vidare
|
|
Navigator.pop(context);
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text("Inlägg skapades!")),
|
|
);
|
|
},
|
|
child: const Text("Publicera"),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|