~garritfra/FlutterFlux

fedeb9169c3c235ae6f3bbba9da79d75dc9fe680 — Garrit Franke 3 years ago adcf7c8
feat: config screen
3 files changed, 83 insertions(+), 2 deletions(-)

A lib/config.dart
M lib/main.dart
A lib/views/user_input_view.dart
A lib/config.dart => lib/config.dart +4 -0
@@ 0,0 1,4 @@
class Config {
  static final IDENTIFIER_LOCALSTORAGE = "flutter_flux";
  static final IDENTIFIER_API_KEY = "api_key";
}

M lib/main.dart => lib/main.dart +22 -2
@@ 1,4 1,7 @@
import 'package:flutter/material.dart';
import 'package:flutterflux/config.dart';
import 'package:flutterflux/views/user_input_view.dart';
import 'package:localstorage/localstorage.dart';

void main() {
  runApp(MyApp());


@@ 12,7 15,13 @@ class MyApp extends StatelessWidget {
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
      initialRoute: "/",
      routes: {
        "/": (ctx) => MyHomePage(
              title: "Unread",
            ),
        "/config": (ctx) => UserInputView(),
      },
    );
  }
}


@@ 27,8 36,19 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {
  final LocalStorage storage = new LocalStorage(Config.IDENTIFIER_LOCALSTORAGE);

  @override
  Widget build(BuildContext context) {
    /// Check if the user token is set.
    /// If that's not the case, redirect to the corresponding page
    void checkToken() {
      String token = storage.getItem(Config.IDENTIFIER_API_KEY);
      if (token == null || token.isEmpty) {
        Navigator.pushNamed(context, "/config");
      }
    }

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),


@@ 36,7 56,7 @@ class _MyHomePageState extends State<MyHomePage> {
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[],
          children: <Widget>[MaterialButton(onPressed: checkToken)],
        ),
      ),
    );

A lib/views/user_input_view.dart => lib/views/user_input_view.dart +57 -0
@@ 0,0 1,57 @@
import 'package:flutter/material.dart';

class UserInputView extends StatefulWidget {
  @override
  _UserInputViewState createState() => _UserInputViewState();
}

class _UserInputViewState extends State<UserInputView> {
  void _onSubmit() {}
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Configuration"),
      ),
      body: Container(
        child: Center(
          child: SizedBox(
            width: 400.0,
            child: Padding(
              padding: EdgeInsets.all(10.0),
              child: ListView(
                children: [
                  Expanded(
                    child: Container(
                      padding: EdgeInsets.all(5.0),
                      child: TextField(
                        decoration: InputDecoration(
                            border: OutlineInputBorder(), labelText: "Server"),
                      ),
                    ),
                  ),
                  Expanded(
                    child: Container(
                      padding: EdgeInsets.all(5.0),
                      child: TextField(
                        decoration: InputDecoration(
                            border: OutlineInputBorder(), labelText: "API Key"),
                      ),
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.all(5.0),
                    child: ElevatedButton(
                      onPressed: _onSubmit,
                      child: Text("Save"),
                    ),
                  )
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}