2019-07-10 14:16:13 +02:00
import ' package:flutter/material.dart ' ;
2019-07-16 23:37:18 +02:00
import ' package:preferences/preferences.dart ' ;
2019-07-25 16:44:51 +02:00
import ' package:provider/provider.dart ' ;
import ' package:toolheim/data/github_adapter.dart ' ;
2019-07-10 14:16:13 +02:00
class SettingsScreen extends StatelessWidget {
@ override
Widget build ( BuildContext context ) {
2019-07-25 16:44:51 +02:00
GitHubAdapter github = Provider . of < GitHubAdapter > ( context ) ;
2019-07-10 14:16:13 +02:00
return Scaffold (
2019-07-12 00:30:57 +02:00
appBar: AppBar ( title: Text ( ' Settings ' ) ) ,
2019-07-16 23:37:18 +02:00
body: PreferencePage ( [
PreferenceTitle ( ' GitHub ' ) ,
PreferenceText (
' Provide a valid GitHub repository with username and project (username/repository-name). This repository must contain warband roster files in subfolders. See the sample project for a kickstart. ' ) ,
TextFieldPreference ( ' Repository ' , ' repository ' ) ,
PreferenceText (
' If your warband folders are placed in a subfolder, you can specify it here. ' ) ,
2019-07-25 16:44:51 +02:00
TextFieldPreference ( ' Path ' , ' path ' , defaultVal: ' / ' ) ,
PreferenceTitle ( ' Search for Warbands ' ) ,
PreferenceText (
' Search the given GitHub repository for valid Warband files (ending with .warband.yml). This step can be done at any time. ' ) ,
FlatButton (
onPressed: ( ) {
github . search ( ) ;
showDialog (
context: context ,
builder: ( BuildContext context ) {
return AlertDialog (
title: Text ( ' Search Warbands ... ' ) ,
content: Column (
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
Text (
' Checking the GitHub repository for suitable files. This can take a while. ' ) ,
SizedBox (
height: 50 ,
) ,
2019-08-02 00:21:41 +02:00
if ( github . isSyncInProgress )
CircularProgressIndicator ( ) ,
if ( github . syncErrors . length > 0 )
buildSyncErrors ( context ) ,
2019-07-25 16:44:51 +02:00
] ) ,
actions: < Widget > [
2019-08-02 00:21:41 +02:00
if ( ! github . isSyncInProgress )
FlatButton (
2019-07-25 16:44:51 +02:00
child: Text ( ' Close ' ,
style: TextStyle ( color: Colors . blue ) ) ,
onPressed: ( ) {
if ( github . syncErrors . length > 0 ) {
Navigator . pop ( context ) ;
} else {
Navigator . popAndPushNamed ( context , ' / ' ) ;
}
} ,
2019-08-02 00:21:41 +02:00
)
2019-07-25 16:44:51 +02:00
] ) ;
} ) ;
} ,
child:
Text ( ' Start search ' , style: TextStyle ( color: Colors . blue ) ) ) ,
2019-07-12 00:30:57 +02:00
] ) ) ;
2019-07-16 23:37:18 +02:00
//String _repository = 'Labernator/Mordheim';
//String _path = 'Mordheim-BorderTownBurning/Warband Rosters';
2019-07-10 14:16:13 +02:00
}
2019-07-25 16:44:51 +02:00
2019-08-01 00:05:42 +02:00
static Widget buildSyncErrors ( BuildContext context ) {
2019-07-25 16:44:51 +02:00
GitHubAdapter github = Provider . of < GitHubAdapter > ( context ) ;
2019-08-02 00:21:41 +02:00
return Column ( children: [
for ( var error in github . syncErrors )
Text ( error , style: TextStyle ( color: Colors . red ) )
] ) ;
2019-07-25 16:44:51 +02:00
}
2019-07-10 14:16:13 +02:00
}