mirror of
https://github.com/hanskokx/arcane_framework.git
synced 2026-05-14 02:19:08 +02:00
Added logStream to logger. Updated example code.
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
+171
-81
@@ -1,3 +1,5 @@
|
||||
import "dart:async";
|
||||
|
||||
import "package:arcane_framework/arcane_framework.dart";
|
||||
import "package:example/config.dart";
|
||||
import "package:example/interfaces/debug_auth_interface.dart";
|
||||
@@ -78,102 +80,174 @@ class HomeScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
late final StreamSubscription<String> _subscription;
|
||||
final List<String> latestLogs = [];
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bool isSignedIn = Arcane.auth.isSignedIn.value;
|
||||
return GridView.extent(
|
||||
maxCrossAxisExtent: 300,
|
||||
padding: const EdgeInsets.all(16),
|
||||
return Column(
|
||||
children: [
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
"Theme",
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
Switch(
|
||||
value: Arcane.theme.currentTheme == ThemeMode.dark,
|
||||
thumbIcon: WidgetStateProperty.resolveWith((states) {
|
||||
if (states.contains(WidgetState.selected)) {
|
||||
return const Icon(Icons.dark_mode);
|
||||
}
|
||||
return const Icon(Icons.light_mode);
|
||||
}),
|
||||
onChanged: (_) {
|
||||
Arcane.theme.switchTheme();
|
||||
},
|
||||
),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Checkbox(
|
||||
value: Arcane.theme.isFollowingSystemTheme,
|
||||
onChanged: (value) {
|
||||
if (value == true) {
|
||||
Arcane.theme.followSystemTheme(context);
|
||||
} else {
|
||||
Arcane.theme.switchTheme(
|
||||
themeMode: Arcane.theme.systemTheme,
|
||||
Expanded(
|
||||
child: GridView.extent(
|
||||
maxCrossAxisExtent: 300,
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
"Theme",
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
Switch(
|
||||
value: Arcane.theme.currentTheme == ThemeMode.dark,
|
||||
thumbIcon:
|
||||
WidgetStateProperty.resolveWith((states) {
|
||||
if (states.contains(WidgetState.selected)) {
|
||||
return const Icon(Icons.dark_mode);
|
||||
}
|
||||
return const Icon(Icons.light_mode);
|
||||
}),
|
||||
onChanged: (_) {
|
||||
final ThemeMode oldTheme =
|
||||
Arcane.theme.currentTheme;
|
||||
Arcane.theme.switchTheme();
|
||||
Arcane.log(
|
||||
"Switching theme",
|
||||
metadata: {
|
||||
"followingSystemTheme":
|
||||
"${Arcane.theme.isFollowingSystemTheme}",
|
||||
"newMode": Arcane.theme.currentTheme.name,
|
||||
"oldMode": oldTheme.name,
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
const Text("Follow system"),
|
||||
],
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Checkbox(
|
||||
value: Arcane.theme.isFollowingSystemTheme,
|
||||
onChanged: (value) {
|
||||
final ThemeMode oldTheme =
|
||||
Arcane.theme.currentTheme;
|
||||
if (value == true) {
|
||||
Arcane.theme.followSystemTheme(context);
|
||||
Arcane.log(
|
||||
"Switching theme",
|
||||
metadata: {
|
||||
"followingSystemTheme":
|
||||
"${Arcane.theme.isFollowingSystemTheme}",
|
||||
"newMode":
|
||||
Arcane.theme.currentTheme.name,
|
||||
"oldMode": oldTheme.name,
|
||||
},
|
||||
);
|
||||
} else {
|
||||
Arcane.theme.switchTheme(
|
||||
themeMode: Arcane.theme.systemTheme,
|
||||
);
|
||||
Arcane.log(
|
||||
"Switching theme",
|
||||
metadata: {
|
||||
"followingSystemTheme":
|
||||
"${Arcane.theme.isFollowingSystemTheme}",
|
||||
"newMode":
|
||||
Arcane.theme.currentTheme.name,
|
||||
"oldMode": oldTheme.name,
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
const Text("Follow system"),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
"The current theme mode is ${context.themeMode.name} and\n"
|
||||
"is ${Arcane.theme.isFollowingSystemTheme ? "" : "not "}"
|
||||
"following the system theme.",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
"The current theme mode is ${context.themeMode.name} and\n"
|
||||
"is ${Arcane.theme.isFollowingSystemTheme ? "" : "not "}"
|
||||
"following the system theme.",
|
||||
),
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
"Authentication",
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text(isSignedIn ? "Sign out" : "Sign in"),
|
||||
onPressed: () async {
|
||||
if (isSignedIn) {
|
||||
await Arcane.auth.logOut(
|
||||
onLoggedOut: () async {
|
||||
setState(() {});
|
||||
},
|
||||
);
|
||||
} else {
|
||||
await Arcane.auth.login<Credentials>(
|
||||
input: (
|
||||
email: "email",
|
||||
password: "password",
|
||||
),
|
||||
onLoggedIn: () async {
|
||||
setState(() {});
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
Center(
|
||||
child: Text("Status: ${Arcane.auth.status.name}"),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: SizedBox(
|
||||
height: 200,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"Authentication",
|
||||
"Logging",
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
ElevatedButton(
|
||||
child: Text(isSignedIn ? "Sign out" : "Sign in"),
|
||||
onPressed: () async {
|
||||
if (isSignedIn) {
|
||||
await Arcane.auth.logOut(
|
||||
onLoggedOut: () async {
|
||||
setState(() {});
|
||||
},
|
||||
);
|
||||
} else {
|
||||
await Arcane.auth.login<Credentials>(
|
||||
input: (
|
||||
email: "email",
|
||||
password: "password",
|
||||
if (latestLogs.isEmpty)
|
||||
Text(
|
||||
"Log messages will appear here",
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
onLoggedIn: () async {
|
||||
setState(() {});
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
Center(
|
||||
child: Text("Status: ${Arcane.auth.status.name}"),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: latestLogs.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Text(latestLogs[index]);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -182,4 +256,20 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_subscription = Arcane.logger.logStream.listen((message) {
|
||||
setState(() {
|
||||
latestLogs.insert(0, message);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_subscription.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user