-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from eloiJhn/feature/dashboard
Feature/dashboard
- Loading branch information
Showing
12 changed files
with
624 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_dotenv/flutter_dotenv.dart'; | ||
import 'package:fluttertoast/fluttertoast.dart'; | ||
import 'package:trelltech/models/board.dart'; | ||
import 'package:trelltech/models/trello_organization.dart'; | ||
import 'package:trelltech/repositories/api.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:trelltech/repositories/authentification.dart'; | ||
|
||
class CreateBoardScreen extends StatefulWidget { | ||
const CreateBoardScreen({Key? key}) : super(key: key); | ||
|
||
@override | ||
_CreateBoardScreenState createState() => _CreateBoardScreenState(); | ||
} | ||
|
||
class _CreateBoardScreenState extends State<CreateBoardScreen> { | ||
final _formKey = GlobalKey<FormState>(); | ||
late TextEditingController _nameController; | ||
late TextEditingController _descriptionController; | ||
late bool _isLoading = false; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_nameController = TextEditingController(); | ||
_descriptionController = TextEditingController(); | ||
} | ||
|
||
void _submitForm() async { | ||
if (_formKey.currentState!.validate()) { | ||
setState(() { | ||
_isLoading = true; | ||
}); | ||
|
||
String? apiKey = dotenv.env['TRELLO_API_KEY']; | ||
String? accessToken = await getAccessToken(); | ||
|
||
if (apiKey == null || accessToken == null) { | ||
Fluttertoast.showToast( | ||
msg: "API key or access token is null", | ||
toastLength: Toast.LENGTH_SHORT, | ||
gravity: ToastGravity.BOTTOM, | ||
timeInSecForIosWeb: 1, | ||
backgroundColor: Colors.red, | ||
textColor: Colors.white, | ||
fontSize: 16.0, | ||
); | ||
setState(() { | ||
_isLoading = false; | ||
}); | ||
return; | ||
} | ||
|
||
try { | ||
await createWorkspace(apiKey, accessToken, _nameController.text); | ||
|
||
Fluttertoast.showToast( | ||
msg: AppLocalizations.of(context)!.boardCreated, | ||
toastLength: Toast.LENGTH_SHORT, | ||
gravity: ToastGravity.BOTTOM, | ||
timeInSecForIosWeb: 1, | ||
backgroundColor: Colors.green, | ||
textColor: Colors.white, | ||
fontSize: 16.0, | ||
); | ||
Navigator.pop(context, 'organizationCreated'); | ||
} catch (e) { | ||
Fluttertoast.showToast( | ||
msg: AppLocalizations.of(context)!.boardCreationFailed, | ||
toastLength: Toast.LENGTH_SHORT, | ||
gravity: ToastGravity.BOTTOM, | ||
timeInSecForIosWeb: 1, | ||
backgroundColor: Colors.red, | ||
textColor: Colors.white, | ||
fontSize: 16.0, | ||
); | ||
} | ||
|
||
setState(() { | ||
_isLoading = false; | ||
}); | ||
} | ||
} | ||
|
||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text(AppLocalizations.of(context)!.boardCreated), | ||
), | ||
body: _isLoading | ||
? const Center(child: CircularProgressIndicator()) | ||
: Padding( | ||
padding: const EdgeInsets.all(16.0), | ||
child: Form( | ||
key: _formKey, | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: <Widget>[ | ||
TextFormField( | ||
controller: _nameController, | ||
decoration: InputDecoration( | ||
labelText: AppLocalizations.of(context)!.boardName, | ||
border: const OutlineInputBorder(), | ||
), | ||
validator: (value) { | ||
if (value!.isEmpty) { | ||
return AppLocalizations.of(context)!.requiredField; | ||
} | ||
return null; | ||
}, | ||
), | ||
const SizedBox(height: 16.0), | ||
TextFormField( | ||
controller: _descriptionController, | ||
decoration: InputDecoration( | ||
labelText: AppLocalizations.of(context)!.boardDescription, | ||
border: const OutlineInputBorder(), | ||
), | ||
maxLines: 4, | ||
), | ||
const SizedBox(height: 16.0), | ||
ElevatedButton( | ||
onPressed: _submitForm, | ||
style: ElevatedButton.styleFrom( | ||
foregroundColor: Colors.white, backgroundColor: Color(0xFF1C39A1), | ||
), | ||
child: Text( | ||
AppLocalizations.of(context)!.boardCreated, | ||
style: const TextStyle(fontSize: 16.0), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
Oops, something went wrong.