| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import 'package:flutter/material.dart';
- import 'package:physigo/friends/services/friends_service.dart';
- class AddFriend extends StatefulWidget {
- const AddFriend({Key? key}) : super(key: key);
- @override
- State<AddFriend> createState() => _AddFriendState();
- }
- class _AddFriendState extends State<AddFriend> {
- late final TextEditingController _controller;
- @override
- void initState() {
- _controller = TextEditingController();
- super.initState();
- }
- void _addFriend() async {
- try {
- await FriendsService.addFriend(_controller.text);
- _controller.clear();
- _showSnackBar("Friend request sent!", Colors.green);
- } catch (error) {
- _showSnackBar(error.toString(), Colors.red);
- }
- }
- void _showSnackBar(String message, Color color) {
- ScaffoldMessenger.of(context).showSnackBar(SnackBar(
- content: Text(message),
- backgroundColor: color,
- duration: const Duration(milliseconds: 1500),
- ));
- }
- @override
- Widget build(BuildContext context) {
- return Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- TextField(
- onSubmitted: (_) => _addFriend(),
- controller: _controller,
- decoration: const InputDecoration(
- border: OutlineInputBorder(),
- hintText: "Enter a friend's ID to add them",
- ),
- ),
- const SizedBox(height: 32),
- ElevatedButton(
- onPressed: _addFriend,
- style: ElevatedButton.styleFrom(
- padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 32),
- ),
- child: const Text("ADD",
- style: TextStyle(
- fontSize: 20,
- fontWeight: FontWeight.bold,
- letterSpacing: 1.3,
- )),
- )
- ],
- );
- }
- }
|