Last active
May 3, 2023 18:58
-
-
Save chimon2000/f543fd97d233147ab10355cd3699afac to your computer and use it in GitHub Desktop.
Revisions
-
chimon2000 revised this gist
May 3, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -88,7 +88,7 @@ class CounterScope extends InheritedNotifier<CounterController> { context.dependOnInheritedWidgetOfExactType<CounterScope>(); assert(result != null, 'No CounterScope found in context'); assert(result!.notifier != null, 'No CounterController found in context'); return result!.notifier!; } -
chimon2000 revised this gist
May 3, 2023 . 1 changed file with 27 additions and 27 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -49,6 +49,33 @@ class HomePage extends StatelessWidget { } } class CounterDisplay extends StatelessWidget { const CounterDisplay({super.key}); @override Widget build(BuildContext context) { return Text( '${CounterScope.of(context).value}', style: Theme.of(context).textTheme.headlineMedium, ); } } class IncrementButton extends StatelessWidget { const IncrementButton({super.key}); @override Widget build(BuildContext context) { return Builder( builder: (context) => FloatingActionButton( onPressed: CounterScope.of(context).increment, tooltip: 'Increment', child: const Icon(Icons.add), ), ); } } class CounterScope extends InheritedNotifier<CounterController> { const CounterScope({ super.key, @@ -78,30 +105,3 @@ class CounterController extends ValueNotifier<int> { value = value - 1; } } -
chimon2000 revised this gist
May 3, 2023 . 1 changed file with 22 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,8 @@ import 'package:flutter/material.dart'; void main() => runApp(CounterApp()); class CounterApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( @@ -15,13 +11,13 @@ class MyApp extends StatelessWidget { theme: ThemeData( primarySwatch: Colors.blue, ), home: const HomePage(title: 'Flutter Demo Home Page'), ); } } class HomePage extends StatelessWidget { const HomePage({ Key? key, required this.title, }) : super(key: key); @@ -30,7 +26,6 @@ class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { return CounterScope( notifier: CounterController(), child: Scaffold( @@ -48,13 +43,7 @@ class MyHomePage extends StatelessWidget { ], ), ), floatingActionButton: const IncrementButton(), ), ); } @@ -72,7 +61,7 @@ class CounterScope extends InheritedNotifier<CounterController> { context.dependOnInheritedWidgetOfExactType<CounterScope>(); assert(result != null, 'No CounterScope found in context'); assert(result!.notifier != null, 'No CounterScope found in context'); return result!.notifier!; } @@ -101,3 +90,18 @@ class CounterDisplay extends StatelessWidget { ); } } class IncrementButton extends StatelessWidget { const IncrementButton({super.key}); @override Widget build(BuildContext context) { return Builder( builder: (context) => FloatingActionButton( onPressed: CounterScope.of(context).increment, tooltip: 'Increment', child: const Icon(Icons.add), ), ); } } -
chimon2000 revised this gist
May 3, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,7 +72,7 @@ class CounterScope extends InheritedNotifier<CounterController> { context.dependOnInheritedWidgetOfExactType<CounterScope>(); assert(result != null, 'No CounterScope found in context'); assert(result!.notifier != null, 'No CounterController found in context'); return result!.notifier!; } -
chimon2000 created this gist
May 3, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,103 @@ // Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', debugShowCheckedModeBanner: false, theme: ThemeData( primarySwatch: Colors.blue, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatelessWidget { const MyHomePage({ Key? key, required this.title, }) : super(key: key); final String title; @override Widget build(BuildContext context) { return CounterScope( notifier: CounterController(), child: Scaffold( appBar: AppBar( title: Text(title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: const [ Text( 'You have pushed the button this many times:', ), CounterDisplay(), ], ), ), floatingActionButton: Builder( builder: (context) => FloatingActionButton( onPressed: CounterScope.of(context).increment, tooltip: 'Increment', child: const Icon(Icons.add), ), ), ), ); } } class CounterScope extends InheritedNotifier<CounterController> { const CounterScope({ super.key, required super.child, super.notifier, }); static CounterController of(BuildContext context) { final CounterScope? result = context.dependOnInheritedWidgetOfExactType<CounterScope>(); assert(result != null, 'No CounterScope found in context'); assert(result!.notifier != null, 'No CounterScope found in context'); return result!.notifier!; } } class CounterController extends ValueNotifier<int> { CounterController([int initialValue = 0]) : super(initialValue); void increment() { value = value + 1; } void decrement() { value = value - 1; } } class CounterDisplay extends StatelessWidget { const CounterDisplay({super.key}); @override Widget build(BuildContext context) { return Text( '${CounterScope.of(context).value}', style: Theme.of(context).textTheme.headlineMedium, ); } }