mirror of
https://github.com/hanskokx/arcane_framework.git
synced 2026-05-14 02:19:08 +02:00
Fixed a bug in the example
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
+127
-115
@@ -152,38 +152,43 @@ class _ArcaneLoggingExampleState extends State<ArcaneLoggingExample> {
|
|||||||
builder: (context, enabledFeatures, _) {
|
builder: (context, enabledFeatures, _) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: SizedBox(
|
child: Card(
|
||||||
height: 200,
|
child: SizedBox(
|
||||||
child: Column(
|
height: MediaQuery.sizeOf(context).height / 2,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
child: Padding(
|
||||||
children: [
|
padding: const EdgeInsets.all(8.0),
|
||||||
Text(
|
child: Column(
|
||||||
"Logging",
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
style: Theme.of(context).textTheme.headlineSmall,
|
children: [
|
||||||
|
Text(
|
||||||
|
"Logging",
|
||||||
|
style: Theme.of(context).textTheme.headlineSmall,
|
||||||
|
),
|
||||||
|
if (latestLogs.isEmpty)
|
||||||
|
Text(
|
||||||
|
"Log messages will appear here",
|
||||||
|
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||||
|
fontStyle: FontStyle.italic,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (Feature.logging.disabled)
|
||||||
|
Text(
|
||||||
|
"Logging feature is disabled.",
|
||||||
|
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: latestLogs.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return Text(latestLogs[index]);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
if (latestLogs.isEmpty)
|
),
|
||||||
Text(
|
|
||||||
"Log messages will appear here",
|
|
||||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
|
||||||
fontStyle: FontStyle.italic,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (Feature.logging.disabled)
|
|
||||||
Text(
|
|
||||||
"Logging feature is disabled.",
|
|
||||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: ListView.builder(
|
|
||||||
itemCount: latestLogs.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return Text(latestLogs[index]);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -544,98 +549,105 @@ class ArcaneServicesExample extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final FavoriteColorService? service =
|
final FavoriteColorService? service =
|
||||||
ArcaneServiceProvider.serviceOfType<FavoriteColorService>(context);
|
ArcaneServiceProvider.serviceOfType<FavoriteColorService>(context);
|
||||||
return Card(
|
final ValueNotifier<MaterialColor?> notifier =
|
||||||
child: Padding(
|
service?.notifier ?? ValueNotifier(null);
|
||||||
padding: const EdgeInsets.all(8.0),
|
return ValueListenableBuilder(
|
||||||
child: Column(
|
valueListenable: notifier,
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
builder: (context, color, _) {
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
return Card(
|
||||||
children: [
|
child: Padding(
|
||||||
Text(
|
padding: const EdgeInsets.all(8.0),
|
||||||
"Services",
|
child: Column(
|
||||||
style: Theme.of(context).textTheme.headlineSmall,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
),
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
ValueListenableBuilder(
|
children: [
|
||||||
valueListenable: ArcaneService.ofType<FavoriteColorService>(
|
Text(
|
||||||
context,
|
"Services",
|
||||||
)?.notifier ??
|
style: Theme.of(context).textTheme.headlineSmall,
|
||||||
ValueNotifier(null),
|
),
|
||||||
builder: (context, color, _) {
|
Text(
|
||||||
return Text(
|
|
||||||
color != null ? "Favorite color: ${color.name}" : "",
|
color != null ? "Favorite color: ${color.name}" : "",
|
||||||
);
|
),
|
||||||
},
|
ElevatedButton(
|
||||||
),
|
onPressed: () {
|
||||||
ElevatedButton(
|
if (service == null) {
|
||||||
onPressed: () {
|
ArcaneServiceProvider.of(context).addService(
|
||||||
if (service == null) {
|
FavoriteColorService.I,
|
||||||
ArcaneServiceProvider.of(context).addService(
|
);
|
||||||
FavoriteColorService.I,
|
|
||||||
);
|
|
||||||
|
|
||||||
Arcane.log(
|
Arcane.log(
|
||||||
"Service registered.",
|
"Service registered.",
|
||||||
metadata: {"service": "FavoriteColorService"},
|
metadata: {"service": "FavoriteColorService"},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
ArcaneServiceProvider.of(context)
|
ArcaneServiceProvider.of(context)
|
||||||
.removeService<FavoriteColorService>();
|
.removeService<FavoriteColorService>();
|
||||||
|
|
||||||
Arcane.log(
|
Arcane.log(
|
||||||
"Service removed.",
|
"Service removed.",
|
||||||
metadata: {"service": "FavoriteColorService"},
|
metadata: {"service": "FavoriteColorService"},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Text('${service == null ? 'Register' : 'Remove'} service'),
|
child: Text(
|
||||||
),
|
'${service == null ? 'Register' : 'Remove'} service',
|
||||||
SizedBox(
|
),
|
||||||
height: 20,
|
),
|
||||||
child: Row(
|
SizedBox(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
height: 20,
|
||||||
spacing: 8,
|
child: Row(
|
||||||
children: [
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
const Text("Color"),
|
spacing: 8,
|
||||||
Expanded(
|
children: [
|
||||||
child: ListView.separated(
|
const Text("Color"),
|
||||||
itemCount: colors.length,
|
Expanded(
|
||||||
scrollDirection: Axis.horizontal,
|
child: ListView.separated(
|
||||||
separatorBuilder: (_, __) => const SizedBox(width: 4),
|
itemCount: colors.length,
|
||||||
itemBuilder: (context, index) {
|
scrollDirection: Axis.horizontal,
|
||||||
return InkWell(
|
separatorBuilder: (_, __) => const SizedBox(width: 4),
|
||||||
onTap: () {
|
itemBuilder: (context, index) {
|
||||||
service?.setMyFavoriteColor(colors[index]);
|
return InkWell(
|
||||||
Arcane.log(
|
onTap: () {
|
||||||
"Set a color in FavoriteColorService",
|
if (service == null) {
|
||||||
metadata: {
|
Arcane.log(
|
||||||
"color": colors[index].name ?? "Unknown",
|
"FavoriteColorService is not registered",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
service.setMyFavoriteColor(colors[index]);
|
||||||
|
Arcane.log(
|
||||||
|
"Set a color in FavoriteColorService",
|
||||||
|
metadata: {
|
||||||
|
"color": colors[index].name ?? "Unknown",
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: colors[index],
|
||||||
|
border: color?.name == colors[index].name
|
||||||
|
? Border.all(width: 2)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: Container(
|
),
|
||||||
decoration: BoxDecoration(
|
),
|
||||||
color: colors[index],
|
],
|
||||||
border: service?.myFavoriteColor?.name ==
|
|
||||||
colors[index].name
|
|
||||||
? Border.all(width: 2)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
Text(
|
||||||
|
"Service is ${service != null ? "" : "not "}registered",
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
Text(
|
),
|
||||||
"Service is ${service != null ? "" : "not "}registered",
|
);
|
||||||
),
|
},
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user