From 13743e93c44483394c8578bb0db9603bdaebc883 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 28 Jan 2021 15:25:30 -0800 Subject: [PATCH] Consumer Pattern --- lib/main.dart | 3 +- lib/views/globalsettingsview.dart | 64 +++++++++++++++++-------------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 2ce42d3..2c34e21 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -102,7 +102,8 @@ class FlwtchState extends State { print("FlwtchState.build() cwtchInit: $cwtchInit"); return MultiProvider( providers: [getFlwtchStateProvider(), getOpaqueProvider()], - builder: (context, widget) { return MaterialApp( + builder: (context, widget) { + return MaterialApp( title: 'Cwtch', theme: ThemeData( visualDensity: VisualDensity.adaptivePlatformDensity, diff --git a/lib/views/globalsettingsview.dart b/lib/views/globalsettingsview.dart index bdbe5df..9f1602d 100644 --- a/lib/views/globalsettingsview.dart +++ b/lib/views/globalsettingsview.dart @@ -28,34 +28,40 @@ class _GlobalSettingsViewState extends State { } Widget _buildSettingsList() { - return Center(child:Column( - children: [ - Text("Language"), - TextField( - controller: myController, - onChanged: (text) { - print("First text field: $text"); - }, - ), - Text("Zoom"), - SwitchListTile( - title: const Text('Theme'), - value: Provider.of(context).current() == Opaque.light, - onChanged: (bool value) { - if (value) { - Provider.of(context, listen: false).setLight(); - } else { - Provider.of(context, listen: false).setDark(); - } - }, - secondary: const Icon(Icons.lightbulb_outline), - ), - Text("Experiments enabled"), - Text("Text magnification reference"), - Text("Acknowledgements"), - Text("Version: xxx"), - Text("Built on: xxx"), - ] - )); + return Consumer( + builder: (context, theme, child) { + return Center(child: Column( + children: [ + Text("Language"), + TextField( + controller: myController, + onChanged: (text) { + print("First text field: $text"); + }, + ), + Text("Zoom"), + SwitchListTile( + title: Text('Theme', + style: TextStyle(color: theme.current().mainTextColor())), + value: theme.current() == Opaque.light, + onChanged: (bool value) { + if (value) { + theme.setLight(); + } else { + theme.setDark(); + } + }, + secondary: Icon(Icons.lightbulb_outline, + color: theme.current().mainTextColor()), + ), + Text("Experiments enabled"), + Text("Text magnification reference"), + Text("Acknowledgements"), + Text("Version: xxx"), + Text("Built on: xxx"), + ] + )); + } + ); } }