From ae6189f5851ab5ca306e2a4a922ae0ffe71af9ac Mon Sep 17 00:00:00 2001 From: Julian Currie <> Date: Sat, 13 Feb 2021 15:39:51 +0700 Subject: [PATCH 01/14] Added the provider package and created a User model --- lib/model/user.dart | 4 ++++ pubspec.lock | 15 +++++++++++++++ pubspec.yaml | 1 + 3 files changed, 20 insertions(+) create mode 100644 lib/model/user.dart diff --git a/lib/model/user.dart b/lib/model/user.dart new file mode 100644 index 0000000..0ca61dd --- /dev/null +++ b/lib/model/user.dart @@ -0,0 +1,4 @@ +class User { + String name; + int age; +} diff --git a/pubspec.lock b/pubspec.lock index 65e5fc2..397ac4d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -81,6 +81,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0-nullsafety.3" + nested: + dependency: transitive + description: + name: nested + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.4" path: dependency: transitive description: @@ -88,6 +95,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0-nullsafety.1" + provider: + dependency: "direct main" + description: + name: provider + url: "https://pub.dartlang.org" + source: hosted + version: "4.3.3" sky_engine: dependency: transitive description: flutter @@ -151,3 +165,4 @@ packages: version: "2.1.0-nullsafety.3" sdks: dart: ">=2.10.0-110 <2.11.0" + flutter: ">=1.16.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index f6db4d8..545bdb3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,6 +19,7 @@ environment: dependencies: flutter: sdk: flutter + provider: ^4.3.3 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. From 23b669426de3a75c9b4a5bbc3dd4dbcd990f95d8 Mon Sep 17 00:00:00 2001 From: Julian Currie <> Date: Sun, 14 Feb 2021 14:50:13 +0700 Subject: [PATCH 02/14] added initial code with custom input/button and add/delete functions --- lib/main.dart | 5 +- lib/model/user.dart | 4 +- lib/screens/home.dart | 98 ++++++++++++++++++++++++++++------ lib/widget/cheetah_button.dart | 32 +++++++++++ lib/widget/cheetah_input.dart | 35 ++++++++++++ lib/widget/user_list.dart | 44 +++++++++++++++ 6 files changed, 199 insertions(+), 19 deletions(-) create mode 100644 lib/widget/cheetah_button.dart create mode 100644 lib/widget/cheetah_input.dart create mode 100644 lib/widget/user_list.dart diff --git a/lib/main.dart b/lib/main.dart index 38a8a32..0d95563 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,8 +7,11 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( + debugShowCheckedModeBanner: false, theme: ThemeData( - appBarTheme: AppBarTheme(color: Color(0xFFe67e00)), + appBarTheme: AppBarTheme(color: Color(0xFF32CD32)), + primaryColor: Color(0xFF32CD32), + backgroundColor: Color(0xFFDCDCDC), ), home: Home(), ); diff --git a/lib/model/user.dart b/lib/model/user.dart index 0ca61dd..bebf874 100644 --- a/lib/model/user.dart +++ b/lib/model/user.dart @@ -1,4 +1,6 @@ class User { String name; - int age; + String city; + + User(this.name, this.city); } diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 44ef858..6495b11 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -1,31 +1,95 @@ +import 'package:CWCFlutter/model/user.dart'; +import 'package:CWCFlutter/screens/user_list_screen.dart'; +import 'package:CWCFlutter/widget/cheetah_button.dart'; +import 'package:CWCFlutter/widget/cheetah_input.dart'; +import 'package:CWCFlutter/widget/user_list.dart'; import 'package:flutter/material.dart'; -class Home extends StatelessWidget { +class Home extends StatefulWidget { + @override + HomeState createState() => HomeState(); +} + +class HomeState extends State { + String _name; + String _city; + + List userList = []; + + addUser(User user) { + setState(() { + userList.add(user); + }); + } + + deleteUser(User user) { + setState(() { + userList.removeWhere((_user) => _user.name == user.name); + }); + } + + final GlobalKey _formKey = GlobalKey(); + @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(title: Text('Cheetah Coding')), - body: Container( - color: Colors.black, - padding: EdgeInsets.all(16), - child: Center( + backgroundColor: Theme.of(context).backgroundColor, + appBar: AppBar( + title: Text( + "Provider Demo", + style: TextStyle(color: Colors.white), + ), + ), + body: SingleChildScrollView( + padding: EdgeInsets.all(24), + child: Form( + key: _formKey, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Image.asset( - 'assets/images/logo.png', - height: 200, + CheetahInput( + labelText: 'Name', + onSaved: (String value) { + _name = value; + }, ), - SizedBox(height: 24), - Text( - 'Master Branch', - style: TextStyle(fontSize: 36, color: Colors.white), + SizedBox(height: 16), + CheetahInput( + labelText: 'City', + onSaved: (String value) { + _city = value; + }, ), - SizedBox(height: 24), - Text( - 'As you can see, there is not a lot here. Each branch relates to a specific Flutter topic discussed in the videos. Checkout the other branches and Happy browsing!', - style: TextStyle(fontSize: 20, color: Colors.white), + SizedBox(height: 20), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + CheetahButton( + text: 'Add Food', + onPressed: () { + if (!_formKey.currentState.validate()) return; + + _formKey.currentState.save(); + + addUser(User(_name, _city)); + }, + ), + CheetahButton( + text: 'List Screen', + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + UserListScreen(userList, deleteUser), + ), + ); + }, + ), + ], ), + SizedBox(height: 20), + UserList(userList, deleteUser), ], ), ), diff --git a/lib/widget/cheetah_button.dart b/lib/widget/cheetah_button.dart new file mode 100644 index 0000000..dcfbc38 --- /dev/null +++ b/lib/widget/cheetah_button.dart @@ -0,0 +1,32 @@ +import 'package:flutter/material.dart'; + +class CheetahButton extends StatelessWidget { + final String text; + final Function onPressed; + final Color color; + + CheetahButton({ + @required this.text, + @required this.onPressed, + this.color, + }); + + @override + Widget build(BuildContext context) { + return FlatButton( + padding: EdgeInsets.all(16), + color: Theme.of(context).primaryColor, + child: Text( + text, + style: TextStyle( + fontSize: 16, + color: Colors.white, + ), + ), + onPressed: onPressed, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(10)), + ), + ); + } +} diff --git a/lib/widget/cheetah_input.dart b/lib/widget/cheetah_input.dart new file mode 100644 index 0000000..477ac18 --- /dev/null +++ b/lib/widget/cheetah_input.dart @@ -0,0 +1,35 @@ +import 'package:flutter/material.dart'; + +class CheetahInput extends StatelessWidget { + final String labelText; + final Function onSaved; + + CheetahInput({ + @required this.labelText, + @required this.onSaved, + }); + + @override + Widget build(BuildContext context) { + return TextFormField( + decoration: InputDecoration( + fillColor: Colors.white, + filled: true, + labelText: labelText, + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(16), + ), + floatingLabelBehavior: FloatingLabelBehavior.never, + ), + initialValue: '', + validator: (String value) { + if (value.isEmpty) { + return '$labelText is required'; + } + + return null; + }, + onSaved: onSaved, + ); + } +} diff --git a/lib/widget/user_list.dart b/lib/widget/user_list.dart new file mode 100644 index 0000000..2abfb2c --- /dev/null +++ b/lib/widget/user_list.dart @@ -0,0 +1,44 @@ +import 'package:CWCFlutter/model/user.dart'; +import 'package:flutter/material.dart'; + +class UserList extends StatelessWidget { + final List users; + final Function(User) onDelete; + + UserList(this.users, this.onDelete); + + @override + Widget build(BuildContext context) { + return ListView.builder( + shrinkWrap: true, + itemBuilder: (BuildContext context, int index) => Card( + child: Padding( + padding: EdgeInsets.all(16), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Name: ${users[index].name}', + style: TextStyle(fontSize: 18), + ), + Text( + 'City: ${users[index].city}', + style: TextStyle(fontSize: 18), + ), + ], + ), + IconButton( + icon: Icon(Icons.delete), + onPressed: () => onDelete(users[index]), + ) + ], + ), + ), + ), + itemCount: users.length, + ); + } +} From 932baa159d67ca368c61c8ddbe8a1b94df4e8dc8 Mon Sep 17 00:00:00 2001 From: Julian Currie <> Date: Sun, 14 Feb 2021 14:50:38 +0700 Subject: [PATCH 03/14] added missing User list screen --- lib/screens/user_list_screen.dart | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/screens/user_list_screen.dart diff --git a/lib/screens/user_list_screen.dart b/lib/screens/user_list_screen.dart new file mode 100644 index 0000000..2178174 --- /dev/null +++ b/lib/screens/user_list_screen.dart @@ -0,0 +1,38 @@ +import 'package:CWCFlutter/model/user.dart'; +import 'package:CWCFlutter/widget/user_list.dart'; +import 'package:flutter/material.dart'; + +class UserListScreen extends StatefulWidget { + final List users; + final Function(User) onDelete; + + UserListScreen(this.users, this.onDelete); + + @override + _UserListScreenState createState() => _UserListScreenState(); +} + +class _UserListScreenState extends State { + deleteUser(User user) { + setState(() { + widget.onDelete(user); + }); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: Theme.of(context).backgroundColor, + appBar: AppBar( + title: Text( + 'Users', + style: TextStyle(color: Colors.white), + ), + ), + body: Padding( + child: UserList(widget.users, deleteUser), + padding: EdgeInsets.all(8), + ), + ); + } +} From 5eb06809403a046c860b66e0f0f1ceda2da3abec Mon Sep 17 00:00:00 2001 From: Julian Currie <> Date: Sun, 7 Mar 2021 18:22:37 +0700 Subject: [PATCH 04/14] added intl pkg, replaced FlatButton with TextButton for Flutter 2 --- ios/Flutter/.last_build_id | 1 + ios/Flutter/Flutter.podspec | 18 +++++++ ios/Runner.xcodeproj/project.pbxproj | 17 +----- .../contents.xcworkspacedata | 2 +- lib/widget/cheetah_button.dart | 29 +++++----- pubspec.lock | 53 +++++++++++-------- pubspec.yaml | 5 +- 7 files changed, 71 insertions(+), 54 deletions(-) create mode 100644 ios/Flutter/.last_build_id create mode 100644 ios/Flutter/Flutter.podspec diff --git a/ios/Flutter/.last_build_id b/ios/Flutter/.last_build_id new file mode 100644 index 0000000..bb82b1c --- /dev/null +++ b/ios/Flutter/.last_build_id @@ -0,0 +1 @@ +1a1a381ead1ef7899cf6d3ddded5560d \ No newline at end of file diff --git a/ios/Flutter/Flutter.podspec b/ios/Flutter/Flutter.podspec new file mode 100644 index 0000000..5ca3041 --- /dev/null +++ b/ios/Flutter/Flutter.podspec @@ -0,0 +1,18 @@ +# +# NOTE: This podspec is NOT to be published. It is only used as a local source! +# + +Pod::Spec.new do |s| + s.name = 'Flutter' + s.version = '1.0.0' + s.summary = 'High-performance, high-fidelity mobile apps.' + s.description = <<-DESC +Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS. + DESC + s.homepage = 'https://flutter.io' + s.license = { :type => 'MIT' } + s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } + s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s } + s.ios.deployment_target = '8.0' + s.vendored_frameworks = 'Flutter.framework' +end diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 723080e..6e228d5 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -9,11 +9,7 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; @@ -27,8 +23,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -39,13 +33,11 @@ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; - 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; - 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -58,8 +50,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -69,9 +59,7 @@ 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, - 9740EEBA1CF902C7004384FC /* Flutter.framework */, 9740EEB21CF90195004384FC /* Debug.xcconfig */, 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 9740EEB31CF90195004384FC /* Generated.xcconfig */, @@ -203,7 +191,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; @@ -255,7 +243,6 @@ /* Begin XCBuildConfiguration section */ 249021D3217E4FDB00AE95B9 /* Profile */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -331,7 +318,6 @@ }; 97C147031CF9000F007C117D /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -387,7 +373,6 @@ }; 97C147041CF9000F007C117D /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; diff --git a/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 1d526a1..919434a 100644 --- a/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/lib/widget/cheetah_button.dart b/lib/widget/cheetah_button.dart index dcfbc38..32278ed 100644 --- a/lib/widget/cheetah_button.dart +++ b/lib/widget/cheetah_button.dart @@ -13,19 +13,24 @@ class CheetahButton extends StatelessWidget { @override Widget build(BuildContext context) { - return FlatButton( - padding: EdgeInsets.all(16), - color: Theme.of(context).primaryColor, - child: Text( - text, - style: TextStyle( - fontSize: 16, - color: Colors.white, + return Expanded( + child: TextButton( + style: TextButton.styleFrom( + padding: EdgeInsets.all(16), + elevation: 8, + backgroundColor: Theme.of(context).primaryColor, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(10)), + ), ), - ), - onPressed: onPressed, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.all(Radius.circular(10)), + child: Text( + text, + style: TextStyle( + fontSize: 16, + color: Colors.white, + ), + ), + onPressed: onPressed, ), ); } diff --git a/pubspec.lock b/pubspec.lock index 397ac4d..5dea72a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,56 +7,56 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons url: "https://pub.dartlang.org" source: hosted - version: "0.1.2" + version: "1.0.2" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -67,41 +67,48 @@ packages: description: flutter source: sdk version: "0.0.0" + intl: + dependency: "direct main" + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.17.0" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" nested: dependency: transitive description: name: nested url: "https://pub.dartlang.org" source: hosted - version: "0.0.4" + version: "1.0.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" provider: dependency: "direct main" description: name: provider url: "https://pub.dartlang.org" source: hosted - version: "4.3.3" + version: "5.0.0" sky_engine: dependency: transitive description: flutter @@ -113,56 +120,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.16.0 <2.0.0" + dart: ">=2.12.0-0.0 <3.0.0" + flutter: ">=1.16.0" diff --git a/pubspec.yaml b/pubspec.yaml index 545bdb3..8e3ec96 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,11 +19,12 @@ environment: dependencies: flutter: sdk: flutter - provider: ^4.3.3 + provider: ^5.0.0 + intl: ^0.17.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.2 + cupertino_icons: ^1.0.2 dev_dependencies: flutter_test: From 8cd25b3c315c1580c0e0ad7b20a9db38de3792cd Mon Sep 17 00:00:00 2001 From: Julian Currie <> Date: Sun, 7 Mar 2021 18:33:32 +0700 Subject: [PATCH 05/14] added a few mock api functions --- lib/api/cheetah_api.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/api/cheetah_api.dart diff --git a/lib/api/cheetah_api.dart b/lib/api/cheetah_api.dart new file mode 100644 index 0000000..a6a54db --- /dev/null +++ b/lib/api/cheetah_api.dart @@ -0,0 +1,18 @@ +import 'dart:async'; +import 'package:intl/intl.dart'; + +Future getProfileUserName() async { + await Future.delayed(Duration(seconds: 5)); + + return "Julian Currie"; +} + +Future getCurrentTime() async { + await Future.delayed(Duration(seconds: 5)); + + return DateFormat("hh:mm aa").format(DateTime.now()); +} + +Stream getSessionTime() { + return Stream.periodic(Duration(seconds: 1), (sessionTime) => sessionTime++); +} From 6c92f258707531bb05814b218662166c50482436 Mon Sep 17 00:00:00 2001 From: Julian Currie <> Date: Sun, 7 Mar 2021 18:53:25 +0700 Subject: [PATCH 06/14] update app color, adjusted some text and spacing --- lib/main.dart | 4 ++-- lib/screens/home.dart | 9 +++++---- lib/widget/user_list.dart | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 0d95563..1232fc3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -9,8 +9,8 @@ class MyApp extends StatelessWidget { return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData( - appBarTheme: AppBarTheme(color: Color(0xFF32CD32)), - primaryColor: Color(0xFF32CD32), + appBarTheme: AppBarTheme(color: Color(0xFF2F5233)), + primaryColor: Color(0xFF2F5233), backgroundColor: Color(0xFFDCDCDC), ), home: Home(), diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 6495b11..390faef 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -41,7 +41,7 @@ class HomeState extends State { ), ), body: SingleChildScrollView( - padding: EdgeInsets.all(24), + padding: EdgeInsets.all(32), child: Form( key: _formKey, child: Column( @@ -62,10 +62,10 @@ class HomeState extends State { ), SizedBox(height: 20), Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ CheetahButton( - text: 'Add Food', + text: 'Add', onPressed: () { if (!_formKey.currentState.validate()) return; @@ -74,8 +74,9 @@ class HomeState extends State { addUser(User(_name, _city)); }, ), + SizedBox(width: 8), CheetahButton( - text: 'List Screen', + text: 'List', onPressed: () { Navigator.push( context, diff --git a/lib/widget/user_list.dart b/lib/widget/user_list.dart index 2abfb2c..5d5a260 100644 --- a/lib/widget/user_list.dart +++ b/lib/widget/user_list.dart @@ -12,6 +12,7 @@ class UserList extends StatelessWidget { return ListView.builder( shrinkWrap: true, itemBuilder: (BuildContext context, int index) => Card( + elevation: 8, child: Padding( padding: EdgeInsets.all(16), child: Row( From 613fc1281144298306083aa5ad19361d2a518b25 Mon Sep 17 00:00:00 2001 From: Julian Currie <> Date: Wed, 7 Apr 2021 00:46:13 +0700 Subject: [PATCH 07/14] Added the riverpod pkg --- ios/Flutter/Flutter.podspec | 18 ----------- lib/controlller/user_controller.dart | 8 +++++ lib/main.dart | 6 ++-- lib/screens/home.dart | 2 +- pubspec.lock | 47 ++++++++++++++++++++-------- pubspec.yaml | 2 +- 6 files changed, 47 insertions(+), 36 deletions(-) delete mode 100644 ios/Flutter/Flutter.podspec create mode 100644 lib/controlller/user_controller.dart diff --git a/ios/Flutter/Flutter.podspec b/ios/Flutter/Flutter.podspec deleted file mode 100644 index 5ca3041..0000000 --- a/ios/Flutter/Flutter.podspec +++ /dev/null @@ -1,18 +0,0 @@ -# -# NOTE: This podspec is NOT to be published. It is only used as a local source! -# - -Pod::Spec.new do |s| - s.name = 'Flutter' - s.version = '1.0.0' - s.summary = 'High-performance, high-fidelity mobile apps.' - s.description = <<-DESC -Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS. - DESC - s.homepage = 'https://flutter.io' - s.license = { :type => 'MIT' } - s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } - s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s } - s.ios.deployment_target = '8.0' - s.vendored_frameworks = 'Flutter.framework' -end diff --git a/lib/controlller/user_controller.dart b/lib/controlller/user_controller.dart new file mode 100644 index 0000000..0d76054 --- /dev/null +++ b/lib/controlller/user_controller.dart @@ -0,0 +1,8 @@ +import 'package:CWCFlutter/model/user.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +final companyProvider = Provider((_) => 'Cheetah Coding'); + +class UserController extends StateNotifier { + UserController(User state) : super(state); +} diff --git a/lib/main.dart b/lib/main.dart index 1232fc3..218eb18 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -9,9 +9,9 @@ class MyApp extends StatelessWidget { return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData( - appBarTheme: AppBarTheme(color: Color(0xFF2F5233)), - primaryColor: Color(0xFF2F5233), - backgroundColor: Color(0xFFDCDCDC), + appBarTheme: AppBarTheme(color: Color(0xFF064479)), + primaryColor: Color(0xFF064479), + backgroundColor: Color(0xFFb7eeff), ), home: Home(), ); diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 390faef..1f3f58a 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -36,7 +36,7 @@ class HomeState extends State { backgroundColor: Theme.of(context).backgroundColor, appBar: AppBar( title: Text( - "Provider Demo", + "Riverpod Demo", style: TextStyle(color: Colors.white), ), ), diff --git a/pubspec.lock b/pubspec.lock index 5dea72a..715bf37 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -62,11 +62,25 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_riverpod: + dependency: "direct main" + description: + name: flutter_riverpod + url: "https://pub.dartlang.org" + source: hosted + version: "0.14.0" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + freezed_annotation: + dependency: transitive + description: + name: freezed_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "0.14.1" intl: dependency: "direct main" description: @@ -74,6 +88,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.17.0" + json_annotation: + dependency: transitive + description: + name: json_annotation + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.1" matcher: dependency: transitive description: @@ -88,13 +109,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" - nested: - dependency: transitive - description: - name: nested - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" path: dependency: transitive description: @@ -102,13 +116,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" - provider: - dependency: "direct main" + riverpod: + dependency: transitive description: - name: provider + name: riverpod url: "https://pub.dartlang.org" source: hosted - version: "5.0.0" + version: "0.14.0" sky_engine: dependency: transitive description: flutter @@ -128,6 +142,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.10.0" + state_notifier: + dependency: transitive + description: + name: state_notifier + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.0" stream_channel: dependency: transitive description: @@ -171,5 +192,5 @@ packages: source: hosted version: "2.1.0" sdks: - dart: ">=2.12.0-0.0 <3.0.0" - flutter: ">=1.16.0" + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.17.0" diff --git a/pubspec.yaml b/pubspec.yaml index 8e3ec96..bda29c7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,8 +19,8 @@ environment: dependencies: flutter: sdk: flutter - provider: ^5.0.0 intl: ^0.17.0 + flutter_riverpod: ^0.14.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. From 77294accea5f53a2aca0669f8f5f720450aadd52 Mon Sep 17 00:00:00 2001 From: Julian Currie <> Date: Thu, 8 Apr 2021 14:03:58 +0700 Subject: [PATCH 08/14] added the uuid pkg --- pubspec.lock | 14 ++++++++++++++ pubspec.yaml | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pubspec.lock b/pubspec.lock index 715bf37..6fa9aa4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -43,6 +43,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.15.0" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" cupertino_icons: dependency: "direct main" description: @@ -184,6 +191,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" + uuid: + dependency: "direct main" + description: + name: uuid + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.4" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index bda29c7..4959b74 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,13 +14,14 @@ description: A new Flutter project. version: 1.0.0+1 environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.2.2 <3.0.0" dependencies: flutter: sdk: flutter intl: ^0.17.0 flutter_riverpod: ^0.14.0 + uuid: ^3.0.4 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. From ede7fb67cb5774bb6381a8cc77f49f9d34431608 Mon Sep 17 00:00:00 2001 From: Julian Currie <> Date: Wed, 14 Apr 2021 13:29:41 +0700 Subject: [PATCH 09/14] removed the uuid package --- pubspec.lock | 14 -------------- pubspec.yaml | 1 - 2 files changed, 15 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 6fa9aa4..715bf37 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -43,13 +43,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.15.0" - crypto: - dependency: transitive - description: - name: crypto - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.1" cupertino_icons: dependency: "direct main" description: @@ -191,13 +184,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" - uuid: - dependency: "direct main" - description: - name: uuid - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.4" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 4959b74..61e3e40 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,7 +21,6 @@ dependencies: sdk: flutter intl: ^0.17.0 flutter_riverpod: ^0.14.0 - uuid: ^3.0.4 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. From 08178ac5cdcf4637003f4ea35c22c7ede536cf0b Mon Sep 17 00:00:00 2001 From: Julian Currie <> Date: Wed, 14 Apr 2021 15:12:14 +0700 Subject: [PATCH 10/14] removed the intl pkg and getCurrentTime api function --- lib/api/cheetah_api.dart | 7 ------- pubspec.lock | 7 ------- pubspec.yaml | 1 - 3 files changed, 15 deletions(-) diff --git a/lib/api/cheetah_api.dart b/lib/api/cheetah_api.dart index a6a54db..c2ddc1f 100644 --- a/lib/api/cheetah_api.dart +++ b/lib/api/cheetah_api.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'package:intl/intl.dart'; Future getProfileUserName() async { await Future.delayed(Duration(seconds: 5)); @@ -7,12 +6,6 @@ Future getProfileUserName() async { return "Julian Currie"; } -Future getCurrentTime() async { - await Future.delayed(Duration(seconds: 5)); - - return DateFormat("hh:mm aa").format(DateTime.now()); -} - Stream getSessionTime() { return Stream.periodic(Duration(seconds: 1), (sessionTime) => sessionTime++); } diff --git a/pubspec.lock b/pubspec.lock index 715bf37..a03fa66 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -81,13 +81,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.14.1" - intl: - dependency: "direct main" - description: - name: intl - url: "https://pub.dartlang.org" - source: hosted - version: "0.17.0" json_annotation: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 61e3e40..30a82ac 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,7 +19,6 @@ environment: dependencies: flutter: sdk: flutter - intl: ^0.17.0 flutter_riverpod: ^0.14.0 # The following adds the Cupertino Icons font to your application. From 22322c63d40690b2452af56463a9127833278719 Mon Sep 17 00:00:00 2001 From: Julian Currie <> Date: Wed, 14 Apr 2021 15:22:45 +0700 Subject: [PATCH 11/14] added an extra text widget --- lib/screens/home.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 1f3f58a..24c9de8 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -47,6 +47,11 @@ class HomeState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ + Text( + "Cheetah Coding", + style: TextStyle(fontSize: 30), + ), + SizedBox(height: 16), CheetahInput( labelText: 'Name', onSaved: (String value) { From 7b14494bc452452e3c727f2e9fd80e288a5a044c Mon Sep 17 00:00:00 2001 From: Julian Currie <> Date: Thu, 15 Apr 2021 14:26:54 +0700 Subject: [PATCH 12/14] removed user_controller --- lib/controlller/user_controller.dart | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 lib/controlller/user_controller.dart diff --git a/lib/controlller/user_controller.dart b/lib/controlller/user_controller.dart deleted file mode 100644 index 0d76054..0000000 --- a/lib/controlller/user_controller.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'package:CWCFlutter/model/user.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -final companyProvider = Provider((_) => 'Cheetah Coding'); - -class UserController extends StateNotifier { - UserController(User state) : super(state); -} From dae96e0d13265fbfef83c1ff330bf817d64a274d Mon Sep 17 00:00:00 2001 From: Julian Currie <> Date: Thu, 15 Apr 2021 18:49:49 +0700 Subject: [PATCH 13/14] upgraded riverpod to use null saftey --- pubspec.lock | 4 ++-- pubspec.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index a03fa66..ebd1af7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -68,7 +68,7 @@ packages: name: flutter_riverpod url: "https://pub.dartlang.org" source: hosted - version: "0.14.0" + version: "0.14.0+1" flutter_test: dependency: "direct dev" description: flutter @@ -115,7 +115,7 @@ packages: name: riverpod url: "https://pub.dartlang.org" source: hosted - version: "0.14.0" + version: "0.14.0+1" sky_engine: dependency: transitive description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index 30a82ac..66e3267 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,7 +19,7 @@ environment: dependencies: flutter: sdk: flutter - flutter_riverpod: ^0.14.0 + flutter_riverpod: ^0.14.0+1 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. From 1cfc5158aab0efaefd356fd56582f83c43de8981 Mon Sep 17 00:00:00 2001 From: Julian Currie <> Date: Thu, 15 Apr 2021 19:06:08 +0700 Subject: [PATCH 14/14] migrated initial code to use null saftey --- lib/model/user.dart | 4 ++-- lib/screens/home.dart | 12 ++++++------ lib/widget/cheetah_button.dart | 8 ++++---- lib/widget/cheetah_input.dart | 10 +++++----- pubspec.yaml | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/model/user.dart b/lib/model/user.dart index bebf874..9e7d340 100644 --- a/lib/model/user.dart +++ b/lib/model/user.dart @@ -1,6 +1,6 @@ class User { - String name; - String city; + String? name; + String? city; User(this.name, this.city); } diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 24c9de8..76e2843 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -11,8 +11,8 @@ class Home extends StatefulWidget { } class HomeState extends State { - String _name; - String _city; + String? _name; + String? _city; List userList = []; @@ -54,14 +54,14 @@ class HomeState extends State { SizedBox(height: 16), CheetahInput( labelText: 'Name', - onSaved: (String value) { + onSaved: (String? value) { _name = value; }, ), SizedBox(height: 16), CheetahInput( labelText: 'City', - onSaved: (String value) { + onSaved: (String? value) { _city = value; }, ), @@ -72,9 +72,9 @@ class HomeState extends State { CheetahButton( text: 'Add', onPressed: () { - if (!_formKey.currentState.validate()) return; + if (!_formKey.currentState!.validate()) return; - _formKey.currentState.save(); + _formKey.currentState!.save(); addUser(User(_name, _city)); }, diff --git a/lib/widget/cheetah_button.dart b/lib/widget/cheetah_button.dart index 32278ed..d409530 100644 --- a/lib/widget/cheetah_button.dart +++ b/lib/widget/cheetah_button.dart @@ -3,11 +3,11 @@ import 'package:flutter/material.dart'; class CheetahButton extends StatelessWidget { final String text; final Function onPressed; - final Color color; + final Color? color; CheetahButton({ - @required this.text, - @required this.onPressed, + required this.text, + required this.onPressed, this.color, }); @@ -30,7 +30,7 @@ class CheetahButton extends StatelessWidget { color: Colors.white, ), ), - onPressed: onPressed, + onPressed: onPressed as void Function()?, ), ); } diff --git a/lib/widget/cheetah_input.dart b/lib/widget/cheetah_input.dart index 477ac18..ea1e37e 100644 --- a/lib/widget/cheetah_input.dart +++ b/lib/widget/cheetah_input.dart @@ -5,8 +5,8 @@ class CheetahInput extends StatelessWidget { final Function onSaved; CheetahInput({ - @required this.labelText, - @required this.onSaved, + required this.labelText, + required this.onSaved, }); @override @@ -22,14 +22,14 @@ class CheetahInput extends StatelessWidget { floatingLabelBehavior: FloatingLabelBehavior.never, ), initialValue: '', - validator: (String value) { - if (value.isEmpty) { + validator: (String? value) { + if (value!.isEmpty) { return '$labelText is required'; } return null; }, - onSaved: onSaved, + onSaved: onSaved as void Function(String?)?, ); } } diff --git a/pubspec.yaml b/pubspec.yaml index 66e3267..9c2e6ad 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ description: A new Flutter project. version: 1.0.0+1 environment: - sdk: ">=2.2.2 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: