Created
May 19, 2020 16:46
-
-
Save sky1095/f2689ce58ba1c4957342aed3b7387971 to your computer and use it in GitHub Desktop.
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
import 'package:flutter/material.dart'; | |
class SignupPage extends StatefulWidget { | |
SignupPage({ | |
Key key, | |
}) : super(key: key); | |
@override | |
_SignupPageState createState() => _SignupPageState(); | |
} | |
class _SignupPageState extends State<SignupPage> { | |
String localStorage; | |
String sessionStorage; | |
GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>(); | |
@override | |
Widget build(BuildContext context) { | |
// read preference | |
TextEditingController controller = TextEditingController(); | |
localStorage = window.localStorage['local_value'] ?? "No Value Saved"; | |
sessionStorage = | |
window.sessionStorage['session_value'] ?? "No Value Stored"; | |
return Scaffold( | |
key: scaffoldKey, | |
body: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
TextField( | |
controller: controller, | |
decoration: InputDecoration( | |
hintText: "Enter value to store as local & session storage", | |
border: OutlineInputBorder()), | |
), | |
RaisedButton( | |
child: Text("Submit"), | |
onPressed: () { | |
setState(() { | |
if (controller.text.isNotEmpty) { | |
print(controller.text); | |
window.localStorage['local_value'] = controller.text; | |
window.sessionStorage['session_value'] = | |
controller.text; | |
} else { | |
scaffoldKey.currentState.showSnackBar(SnackBar( | |
backgroundColor: Colors.red, | |
content: | |
Text("Please enter a value before submitting..."), | |
)); | |
} | |
}); | |
}, | |
), | |
Text("From Local Storage: " + localStorage), | |
Text("From Session Storage: " + sessionStorage ?? "No value"), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment