diff --git a/android/gradle.properties b/android/gradle.properties index 818e87b23b224ced309ae5c147e5ed827826e237..db7a1ee2908d6e94aeb319e1c1b548a8bb245891 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true -app.versionName=0.0.2 -app.versionCode=2 +app.versionName=0.0.3 +app.versionCode=3 diff --git a/fastlane/metadata/android/en-US/changelogs/3.txt b/fastlane/metadata/android/en-US/changelogs/3.txt new file mode 100644 index 0000000000000000000000000000000000000000..1b54a84b7e64c3d427009894a5d22f38f798f409 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/3.txt @@ -0,0 +1 @@ +Add parameters page with API URL diff --git a/fastlane/metadata/android/fr-FR/changelogs/3.txt b/fastlane/metadata/android/fr-FR/changelogs/3.txt new file mode 100644 index 0000000000000000000000000000000000000000..ec64f525307d2e5f84ebeb176526e2e5663cc7a0 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/3.txt @@ -0,0 +1 @@ +Ajout d'une page de paramétrage avec l'url de l'API diff --git a/lib/main.dart b/lib/main.dart index dd1afff2ab481d34fc88bd2e0751f294b17f42ed..ab6bc3192fb7350c0d77d898ad8037cc25f83ded 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'package:provider/provider.dart'; import 'provider/data.dart'; import 'screens/home.dart'; +import 'screens/settings.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); @@ -26,6 +27,7 @@ class MyApp extends StatelessWidget { home: Home(), routes: { Home.id: (context) => Home(), + SettingsPage.id: (context) => SettingsPage(), }, ); }), diff --git a/lib/provider/data.dart b/lib/provider/data.dart index 26ba51565a5338663d46e626c47259c3d6eb8915..18ce63cdcd35a6c3a9cbc7f8cd2304798bbd4885 100644 --- a/lib/provider/data.dart +++ b/lib/provider/data.dart @@ -1,5 +1,36 @@ import 'package:flutter/foundation.dart'; +import 'package:shared_preferences/shared_preferences.dart'; class Data extends ChangeNotifier { + // Application settings + String _apiurl = ''; + + getParameterValue(String parameterCode) { + switch(parameterCode) { + case 'apiurl': { return _apiurl; } + break; + } + } + + setParameterValue(String parameterCode, String parameterValue) async { + print('set parameter "' + parameterCode + '" to value "' + parameterValue + '"'); + switch(parameterCode) { + case 'apiurl': { updateApiUrl(parameterValue); } + break; + } + final prefs = await SharedPreferences.getInstance(); + prefs.setString(parameterCode, parameterValue); + } + + void initParametersValues() async { + final prefs = await SharedPreferences.getInstance(); + setParameterValue('apiurl', prefs.getString('apiurl') ?? 'http://127.0.0.1/plotter'); + } + + String get apiurl => _apiurl; + void updateApiUrl(String apiurl) { + _apiurl = apiurl; + notifyListeners(); + } } diff --git a/lib/screens/home.dart b/lib/screens/home.dart index fb41b3106deb511afd594f7964ba4dfc030f52c6..221870f09412f50b3e2670c9b94287f98218c604 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -2,10 +2,24 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../provider/data.dart'; +import '../screens/settings.dart'; -class Home extends StatelessWidget { +class Home extends StatefulWidget { static const String id = 'home'; + @override + _HomeState createState() => _HomeState(); +} + +class _HomeState extends State<Home> { + @override + void initState() { + super.initState(); + + Data myProvider = Provider.of<Data>(context, listen: false); + myProvider.initParametersValues(); + } + @override Widget build(BuildContext context) { Data myProvider = Provider.of<Data>(context); @@ -15,8 +29,19 @@ class Home extends StatelessWidget { title: new Text('Stepper plotter assistant'), actions: [ + IconButton( + icon: Icon(Icons.settings), + onPressed: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return SettingsPage(); + }), + ); + }, + ) ], - + leading: IconButton( icon: Image.asset('assets/icons/application.png'), onPressed: () { }, diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart new file mode 100644 index 0000000000000000000000000000000000000000..6e5ce164fc405b534e8ba23b4c136425f610c805 --- /dev/null +++ b/lib/screens/settings.dart @@ -0,0 +1,61 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +import '../provider/data.dart'; + +class SettingsPage extends StatefulWidget { + static const String id = 'settings'; + const SettingsPage({Key? key}) : super(key: key); + + @override + _SettingsPageState createState() => _SettingsPageState(); +} + +class _SettingsPageState extends State<SettingsPage> { + TextEditingController apiUrlFieldController = TextEditingController(); + + @override + void dispose() { + apiUrlFieldController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + Data myProvider = Provider.of<Data>(context); + + apiUrlFieldController.text = myProvider.getParameterValue('apiurl'); + + return Scaffold( + appBar: AppBar( + title: new Text('Stepper - settings'), + + actions: [ + IconButton( + icon: Icon(Icons.save), + onPressed: () { + myProvider.setParameterValue('apiurl', apiUrlFieldController.text); + Navigator.pop(context); + }, + ) + ], + + leading: IconButton( + icon: Image.asset('assets/icons/application.png'), + onPressed: () { }, + ), + ), + + body: Padding( + padding: const EdgeInsets.all(16.0), + child: TextFormField( + controller: apiUrlFieldController, + decoration: InputDecoration( + border: UnderlineInputBorder(), + labelText: 'API URL', + ), + ), + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index b6eca0d9a310f699c2be40fd6273acfa381332e9..9bed09620d00b8ade2770a54031e59727a291b7b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.7.0" + version: "2.8.1" boolean_selector: dependency: transitive description: @@ -50,6 +50,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.0" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.2" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.2" flutter: dependency: "direct main" description: flutter @@ -60,6 +74,18 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + js: + dependency: transitive + description: + name: js + url: "https://pub.dartlang.org" + source: hosted + version: "0.6.3" matcher: dependency: transitive description: @@ -88,6 +114,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.3" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.2" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.3" provider: dependency: "direct main" description: @@ -95,6 +163,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "5.0.0" + shared_preferences: + dependency: "direct main" + description: + name: shared_preferences + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.6" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + shared_preferences_macos: + dependency: transitive + description: + name: shared_preferences_macos + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" sky_engine: dependency: transitive description: flutter @@ -141,7 +251,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.1" + version: "0.4.2" typed_data: dependency: transitive description: @@ -156,6 +266,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.5" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" sdks: - dart: ">=2.12.0 <3.0.0" - flutter: ">=1.16.0" + dart: ">=2.13.0 <3.0.0" + flutter: ">=2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 8180345ae60763afb1c1fa30e987080693523901..d3eb8cbd948fcfe8032954069cc32f086f6bb3c8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,12 +4,13 @@ publish_to: 'none' version: 1.0.0+1 environment: - sdk: ">=2.7.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: sdk: flutter provider: ^5.0.0 + shared_preferences: ^2.0.6 dev_dependencies: flutter_test: