-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: bind(context) #30
Comments
@passsy import 'package:flutter/material.dart';
import 'package:state_beacon/state_beacon.dart';
void main() {
runApp(const LiteRefScope(child: MyApp()));
}
class MyController extends BeaconController {
static final ref = Ref.scoped((context) => MyController());
late final list = B.list<String>(['a', 'b', 'c']);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
final controller = MyController.ref.of(context);
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: Scaffold(
body: Center(
child: Text(
controller.list.watch(context).toString(),
),
),
),
);
}
} |
I actually prefer context_ref's approach to overriding but I found that I don't use the feature much so the nesting isn't much of an issue. I'm not opposed to adding it, but I can't make any guarantees right now. |
Sorry, missed your response @yehorh! I use it in three cases: Theming, Testing and Flavouring. For theming I created my own For testing I inject my dependencies like an I also have multiple Again, everything is already possible. It's just the syntax that feels too verbose when I switch from a |
Coming from
package:provider
I'm testinglite_ref
andcontext_plus
. All get the job done.context_plus
has some interesting (syntactic) features, I'd love to see inlite_ref
, too.bind
With
lite_ref
, passing anything down to the child widgets requires wrapping withLiteRefScope
withoverrides
and a Builder to access it directlyThe syntax it is not a dealbreaker. But it is quite verbose and adds two levels of nesting.
That I have to define
overrides
feels off. It might be the only time I provide a value to child widgets, not overriding anything.Would this
bind
API be possible forlite_ref
, too?The text was updated successfully, but these errors were encountered: