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

docs(console): update flutter intergration guide #6125

Merged
merged 7 commits into from
Jul 1, 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
Prev Previous commit
Next Next commit
chore(console): remove the sample code from guide
remove the sample code from guide
  • Loading branch information
simeng-li committed Jul 1, 2024
commit 42d2c315d2fcf8b2ed2435c1be2e94ad1ec8ac3d
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ This plugin uses `ASWebAuthenticationSession` on iOS 12+ and macOS 10.15+, `SFAu

<Step title="Init Client" subtitle="1 step">

Import the `logto_dart_sdk` package and initialize the `LogtoClient` instance at the root of your application.
Import the `logto_dart_sdk` package and initialize the `LogtoClient` instance at the root widget of your application.

<Code className="language-dart" title="lib/main.dart">
{`import 'package:logto_dart_sdk/logto_dart_sdk.dart';
Expand Down Expand Up @@ -217,102 +217,6 @@ user is signed in, the value will be `true`, otherwise, the value will be `false

<Checkpoint />

<Code className="language-dart" title="lib/main.dart">
{`import 'package:flutter/material.dart';
import 'package:logto_dart_sdk/logto_dart_sdk.dart';
import 'package:http/http.dart' as http;

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

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

@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Flutter Demo',
home: MyHomePage(title: 'Logto Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
late LogtoClient logtoClient;
bool? isAuthenticated = false;

// Update the authentication state
void render() {
setState(() async {
isAuthenticated = await logtoClient.isAuthenticated;
});
}

// LogtoConfig
final logtoConfig = const LogtoConfig(
endpoint: '${props.endpoint}',
appId: '${props.app.id}',
);

void _init() {
logtoClient = LogtoClient(
config: logtoConfig,
httpClient: http.Client(), // Optional http client
);
render();
}

@override
void initState() {
super.initState();
_init();
}

@override
Widget build(BuildContext context) {
Widget signInButton = TextButton(
onPressed: () async {
await logtoClient.signIn('${props.redirectUris[0] ?? 'io.logto://callback'}');
render();
},
child: const Text('Sign In'),
);

Widget signOutButton = TextButton(
onPressed: () async {
await logtoClient.signOut();
render();
},
child: const Text('Sign Out'),
);

return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const SelectableText('My Demo App'),
isAuthenticated ?? false ? signOutButton : signInButton,
],
),
),
);
}
}`}
</Code>

</Step>

</Steps>
Loading