Skip to content

Commit

Permalink
Merge pull request #24 from masewo/master
Browse files Browse the repository at this point in the history
⬆️ Upgrade to Appwrite 12.0.0
  • Loading branch information
lohanidamodar authored Aug 2, 2024
2 parents 360cdb8 + 73bebb8 commit 16440a2
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 146 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [0.10.0]
* Updated to Appwrite SDK 12.0.0
* **BREAKING** Updated naming to be consistent `createEmailSession` is now `createEmailPasswordSession`
* **BREAKING** Updated naming to be consistent `createPhoneSession` is now `createPhoneToken`
* **BREAKING** Updated naming to be consistent `createMagicURLSession` is now `createMagicURLToken`
* **BREAKING** Changed argument `provider` of `createOAuth2Session` from `String` to `OAuthProvider`
* **BREAKING** Removed argument `passwordAgain` of `updateRecovery`

## [0.9.0]
* Updated to Appwrite SDK 11.0.0

## [0.8.0]
* Appwrite 1.3 Support

## [0.7.0]
* Updated to Appwrite SDK 8.2.0

Expand Down
46 changes: 29 additions & 17 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import 'package:appwrite_auth_kit/appwrite_auth_kit.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);

@override
_MyAppState createState() => _MyAppState();
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
Expand All @@ -31,39 +33,43 @@ class _MyAppState extends State<MyApp> {
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MainScreen(),
home: const MainScreen(),
),
);
}
}

class MainScreen extends StatelessWidget {
const MainScreen({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final authNotifier = context.authNotifier;

Widget widget;
switch (authNotifier.status) {
case AuthStatus.authenticated:
widget = AdminPage();
widget = const AdminPage();
break;
case AuthStatus.unauthenticated:
case AuthStatus.authenticating:
widget = LoginPage();
widget = const LoginPage();
break;
case AuthStatus.uninitialized:
default:
widget = LoadingPage();
widget = const LoadingPage();
break;
}
return widget;
}
}

class LoadingPage extends StatelessWidget {
const LoadingPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
return const Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
Expand All @@ -72,12 +78,14 @@ class LoadingPage extends StatelessWidget {
}

class AdminPage extends StatelessWidget {
const AdminPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final user = context.authNotifier.user;
return Scaffold(
appBar: AppBar(
title: Text('Admin page'),
title: const Text('Admin page'),
),
body: ListView(
padding: const EdgeInsets.all(16.0),
Expand All @@ -90,7 +98,7 @@ class AdminPage extends StatelessWidget {
onPressed: () {
context.authNotifier.deleteSession();
},
child: Text("Logout"))
child: const Text("Logout"))
]
],
),
Expand All @@ -99,8 +107,10 @@ class AdminPage extends StatelessWidget {
}

class LoginPage extends StatefulWidget {
const LoginPage({Key? key}) : super(key: key);

@override
_LoginPageState createState() => _LoginPageState();
State<LoginPage> createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
Expand Down Expand Up @@ -137,7 +147,7 @@ class _LoginPageState extends State<LoginPage> {
child: ListView(
shrinkWrap: true,
primary: false,
physics: NeverScrollableScrollPhysics(),
physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.all(16.0),
children: [
const SizedBox(height: 20.0),
Expand All @@ -151,34 +161,36 @@ class _LoginPageState extends State<LoginPage> {
const SizedBox(height: 20.0),
TextField(
controller: _email,
decoration: InputDecoration(
decoration: const InputDecoration(
labelText: "Enter email",
),
),
TextField(
controller: _password,
obscureText: true,
decoration: InputDecoration(
decoration: const InputDecoration(
labelText: "Enter password",
),
),
const SizedBox(height: 30.0),
ElevatedButton(
child: Text("Login"),
onPressed: () async {
final email = _email.text;
final password = _password.text;
final scaffoldMessenger = ScaffoldMessenger.of(context);
final authNotifier = context.authNotifier;

if (!await context.authNotifier.createEmailSession(
if (!await authNotifier.createEmailPasswordSession(
email: email, password: password)) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(context.authNotifier.error ??
scaffoldMessenger.showSnackBar(SnackBar(
content: Text(authNotifier.error ??
"Unknown error")));
}
},
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(16.0),
),
child: const Text("Login"),
),
const SizedBox(height: 20.0),
],
Expand Down
2 changes: 1 addition & 1 deletion example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import window_to_front
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
FlutterWebAuth2Plugin.register(with: registry.registrar(forPlugin: "FlutterWebAuth2Plugin"))
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
WindowToFrontPlugin.register(with: registry.registrar(forPlugin: "WindowToFrontPlugin"))
Expand Down
Loading

0 comments on commit 16440a2

Please sign in to comment.