Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix syntax errors in Flutter quick start #557

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 65 additions & 57 deletions src/routes/docs/quick-starts/flutter/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -182,35 +182,32 @@ import 'package:appwrite/models.dart' as models;

void main() {
WidgetsFlutterBinding.ensureInitialized();
Client client = Client();
client = Client()
Client client = Client()
.setEndpoint("https://cloud.appwrite.io/v1")
.setProject("650209298acac4ee1bb6");
.setProject("<YOUR_PROJECT_ID>");
Account account = Account(client);

runApp(MyApp(
account: account,
runApp(MaterialApp(
home: MyApp(account: account),
));
}
```
{% /section %}
{% section #step-5 step=5 title="Create a login page" %}
Then, append the following widgets to `lib/main.dart` create your login page.
import 'package:appwrite/appwrite.dart';

```dart
class MyForm extends StatefulWidget {
class MyApp extends StatefulWidget {
final Account account;

MyForm({required this.account});
MyApp({required this.account});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are renaming this to MyApp, its better to rename MyFormState to MyAppState as well


@override
MyFormState createState() {
return MyFormState();
}
}
```
{% /section %}
{% section #step-5 step=5 title="Create a login page" %}
Then, append the following widgets to `lib/main.dart` create your login page.

class MyFormState extends State<MyForm> {
```dart
class MyFormState extends State<MyApp> {
models.User? loggedInUser;
final TextEditingController emailController = TextEditingController();
final TextEditingController passwordController = TextEditingController();
Expand Down Expand Up @@ -239,49 +236,60 @@ class MyFormState extends State<MyForm> {

@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(loggedInUser != null
? 'Logged in as ${loggedInUser!.name}'
: 'Not logged in'),
SizedBox(height: 16.0),
TextField(
controller: emailController,
decoration: InputDecoration(labelText: 'Email'),
),
SizedBox(height: 16.0),
TextField(
controller: passwordController,
decoration: InputDecoration(labelText: 'Password'),
obscureText: true,
),
SizedBox(height: 16.0),
TextField(
controller: nameController,
decoration: InputDecoration(labelText: 'Name'),
),
SizedBox(height: 16.0),
ElevatedButton(
onPressed: () {
login(emailController.text, passwordController.text);
},
child: Text('Login'),
),
ElevatedButton(
onPressed: () {
register(emailController.text, passwordController.text,
nameController.text);
},
child: Text('Register'),
),
ElevatedButton(
onPressed: () {
logout();
},
child: Text('Logout'),
return MaterialApp(
home: Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(loggedInUser != null
? 'Logged in as ${loggedInUser!.name}'
: 'Not logged in'),
SizedBox(height: 16.0),
TextField(
controller: emailController,
decoration: InputDecoration(labelText: 'Email'),
),
SizedBox(height: 16.0),
TextField(
controller: passwordController,
decoration: InputDecoration(labelText: 'Password'),
obscureText: true,
),
SizedBox(height: 16.0),
TextField(
controller: nameController,
decoration: InputDecoration(labelText: 'Name'),
),
SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
ElevatedButton(
onPressed: () {
login(emailController.text, passwordController.text);
},
child: Text('Login'),
),
SizedBox(width: 16.0),
ElevatedButton(
onPressed: () {
register(emailController.text, passwordController.text,
nameController.text);
},
child: Text('Register'),
),
SizedBox(width: 16.0),
ElevatedButton(
onPressed: () {
logout();
},
child: Text('Logout'),
),
],
),
],
),
],
),
);
}
}
Expand Down
Loading