diff --git a/.DS_Store b/.DS_Store index eb540be..73c95c8 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/image/.DS_Store b/image/.DS_Store index 6c5f31b..708faf4 100644 Binary files a/image/.DS_Store and b/image/.DS_Store differ diff --git a/image/value_listenable_builder.gif b/image/value_listenable_builder.gif new file mode 100644 index 0000000..92388cd Binary files /dev/null and b/image/value_listenable_builder.gif differ diff --git a/mecury_project/example/flutter_widget_of_the_week/README.md b/mecury_project/example/flutter_widget_of_the_week/README.md index f1ac678..39930b1 100644 --- a/mecury_project/example/flutter_widget_of_the_week/README.md +++ b/mecury_project/example/flutter_widget_of_the_week/README.md @@ -6,61 +6,73 @@ https://www.youtube.com/watch?v=lkF0TQJO0bA&list=PLOU2XLYxmsIL0pH0zWe_ZOHgGhZ7Ua 国内可看[bilibili](https://www.bilibili.com/video/av40410258) 有人搬运,带中文字幕 ## 样例 -### week1 +### week1 SafeArea ![](../../../image/week1.png) -### week2 +### week2 Expanded ![](../../../image/week2.png) -### week3 +### week3 Wrap ![](../../../image/week3.png) -### week4 +### week4 AnimatedContainer ![](../../../image/week4.png) -### week5 +### week5 Opacity ![](../../../image/week5.png) -### week6 +### week6 FutureBuilder ![](../../../image/week6.png) -### week7 +### week7 FadeTransition ![](../../../image/week7.png) -### week8 +### week8 FloatingActionButton ![](../../../image/week8.png) -### week9 +### week9 PageView ![](../../../image/week9.png) -### week10 +### week10 Table ![](../../../image/week10.png) -### week11 +### week11 SliverAppBar ![](../../../image/week11.png) -### week12 +### week12 SliverListGrid ![](../../../image/week12.png) -### week13 +### week13 FadeInImage ![](../../../image/week13.png) -### week14 +### week14 StreamBuilder ![](../../../image/week14.png) -### week15 +### week15 InheritedModel + +![](../../../image/week19.png) + + +### week16 ClipRRect ![](../../../image/week15.png) -### week16 -![](../../../image/week16.png) -### week17 -![](../../../image/week17.png) -### week18 +### Week17 Hero ![](../../../image/week18.png) -### week19 -![](../../../image/week19.png) -### week20 +### Week18 CustomPaint + +![](/workspace/flutter/Flutter-Notebook/image/week17.png) + +### week19 ToolTip + +![](../../../image/week16.png) + +### week20 FittedBox ![](../../../image/week20.png) -### week21 +### week21 LayoutBuilder + ![](../../../image/week21.png) -### week22 +### week22 AbsorbPointer ![](../../../image/week22.png) -### week23 +### week23 Transform ![](../../../image/week23.png) -### week24 +### week24 BackDropFilter ![](../../../image/week24.png) -### week25 +### week25 Align ![](../../../image/week25.png) -### week26 +### week26 Position ![](../../../image/week26.png) -### week27 +### week27 AnimatedBuilder ![](../../../image/week27.png) -### week28 +### week28 Dismissible ![](../../../image/week28.png) -### week29 +### week29 SizedBox ![](../../../image/week29.png) + +### Week30 ValueListenableBuilder + +![value_listenable_builder](/workspace/flutter/Flutter-Notebook/image/value_listenable_builder.gif) \ No newline at end of file diff --git a/mecury_project/example/flutter_widget_of_the_week/lib/main.dart b/mecury_project/example/flutter_widget_of_the_week/lib/main.dart index 9238fb6..1c21c23 100644 --- a/mecury_project/example/flutter_widget_of_the_week/lib/main.dart +++ b/mecury_project/example/flutter_widget_of_the_week/lib/main.dart @@ -40,7 +40,8 @@ class MyApp extends StatelessWidget { // home: Week26(), // home: Week27(), // home: Week28(), - home: Week29(), +// home: Week29(), + home: Week30(), ); } } diff --git a/mecury_project/example/flutter_widget_of_the_week/lib/widget/week30_value_listenable_builder.dart b/mecury_project/example/flutter_widget_of_the_week/lib/widget/week30_value_listenable_builder.dart new file mode 100644 index 0000000..166db8c --- /dev/null +++ b/mecury_project/example/flutter_widget_of_the_week/lib/widget/week30_value_listenable_builder.dart @@ -0,0 +1,68 @@ +import 'package:flutter/material.dart'; + +class Week30 extends StatelessWidget { + final ValueNotifier _counter = ValueNotifier(0); + final ColorProvider _colorProvider = ColorProvider(ColorModel()); + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + ValueListenableBuilder( + valueListenable: _counter, + builder: (context, int value, _) { + return Text('current counter is : $value'); + }), + ValueListenableBuilder( + valueListenable: _colorProvider, + builder: (context, model, _) { + return Container( + height: 100, + width: 100, + color: model.color, + ); + }, + ), + ], + ), + ), + floatingActionButton: FloatingActionButton(onPressed: () { + _counter.value++; + _colorProvider.changeColor(); + }), + ); + } +} + +class ColorModel { + final List _colors = [ + Colors.redAccent, + Colors.lightGreen, + Colors.pinkAccent, + Colors.tealAccent, + Colors.blue, + ]; + int _currentColor = 0; + + get color => _colors[_currentColor]; + + changeColor() { + if (_currentColor != _colors.length - 1) + _currentColor++; + else + _currentColor = 0; + } +} + +class ColorProvider extends ValueNotifier { + ColorProvider(ColorModel value) : super(value); + + changeColor() { + value.changeColor(); + notifyListeners(); + } +} diff --git a/mecury_project/example/flutter_widget_of_the_week/lib/widget/widgets.dart b/mecury_project/example/flutter_widget_of_the_week/lib/widget/widgets.dart index 4452b26..0884655 100644 --- a/mecury_project/example/flutter_widget_of_the_week/lib/widget/widgets.dart +++ b/mecury_project/example/flutter_widget_of_the_week/lib/widget/widgets.dart @@ -26,4 +26,5 @@ export 'week25_align.dart'; export 'week26_position.dart'; export 'week27_animated_builder.dart'; export 'week28_dismissible.dart'; -export 'week29_sizedbox.dart'; \ No newline at end of file +export 'week29_sizedbox.dart'; +export 'week30_value_listenable_builder.dart'; \ No newline at end of file diff --git a/mecury_project/example/provider_example/lib/generated/i18n.dart b/mecury_project/example/provider_example/lib/generated/i18n.dart new file mode 100644 index 0000000..2dcf836 --- /dev/null +++ b/mecury_project/example/provider_example/lib/generated/i18n.dart @@ -0,0 +1,122 @@ +import 'dart:async'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; + +// ignore_for_file: non_constant_identifier_names +// ignore_for_file: camel_case_types +// ignore_for_file: prefer_single_quotes + +// This file is automatically generated. DO NOT EDIT, all your changes would be lost. +class S implements WidgetsLocalizations { + const S(); + + static const GeneratedLocalizationsDelegate delegate = + GeneratedLocalizationsDelegate(); + + static S of(BuildContext context) => Localizations.of(context, S); + + @override + TextDirection get textDirection => TextDirection.ltr; + +} + +class $en extends S { + const $en(); +} + +class GeneratedLocalizationsDelegate extends LocalizationsDelegate { + const GeneratedLocalizationsDelegate(); + + List get supportedLocales { + return const [ + Locale("en", ""), + ]; + } + + LocaleListResolutionCallback listResolution({Locale fallback, bool withCountry = true}) { + return (List locales, Iterable supported) { + if (locales == null || locales.isEmpty) { + return fallback ?? supported.first; + } else { + return _resolve(locales.first, fallback, supported, withCountry); + } + }; + } + + LocaleResolutionCallback resolution({Locale fallback, bool withCountry = true}) { + return (Locale locale, Iterable supported) { + return _resolve(locale, fallback, supported, withCountry); + }; + } + + @override + Future load(Locale locale) { + final String lang = getLang(locale); + if (lang != null) { + switch (lang) { + case "en": + return SynchronousFuture(const $en()); + default: + // NO-OP. + } + } + return SynchronousFuture(const S()); + } + + @override + bool isSupported(Locale locale) => _isSupported(locale, true); + + @override + bool shouldReload(GeneratedLocalizationsDelegate old) => false; + + /// + /// Internal method to resolve a locale from a list of locales. + /// + Locale _resolve(Locale locale, Locale fallback, Iterable supported, bool withCountry) { + if (locale == null || !_isSupported(locale, withCountry)) { + return fallback ?? supported.first; + } + + final Locale languageLocale = Locale(locale.languageCode, ""); + if (supported.contains(locale)) { + return locale; + } else if (supported.contains(languageLocale)) { + return languageLocale; + } else { + final Locale fallbackLocale = fallback ?? supported.first; + return fallbackLocale; + } + } + + /// + /// Returns true if the specified locale is supported, false otherwise. + /// + bool _isSupported(Locale locale, bool withCountry) { + if (locale != null) { + for (Locale supportedLocale in supportedLocales) { + // Language must always match both locales. + if (supportedLocale.languageCode != locale.languageCode) { + continue; + } + + // If country code matches, return this locale. + if (supportedLocale.countryCode == locale.countryCode) { + return true; + } + + // If no country requirement is requested, check if this locale has no country. + if (true != withCountry && (supportedLocale.countryCode == null || supportedLocale.countryCode.isEmpty)) { + return true; + } + } + } + return false; + } +} + +String getLang(Locale l) => l == null + ? null + : l.countryCode != null && l.countryCode.isEmpty + ? l.languageCode + : l.toString(); diff --git a/mecury_project/example/provider_example/lib/screens.dart b/mecury_project/example/provider_example/lib/screens.dart index 5bd51eb..4a8c7d1 100644 --- a/mecury_project/example/provider_example/lib/screens.dart +++ b/mecury_project/example/provider_example/lib/screens.dart @@ -5,7 +5,7 @@ import 'counter_model.dart'; class FirstScreen extends StatelessWidget { @override Widget build(BuildContext context) { - final counter = Provider.of(context); + final counter = Provider.of(context,); final textSize = Provider.of(context); return Scaffold(