瀏覽代碼

feat: get package, name change controller

Fela Maslen 4 年之前
父節點
當前提交
8ef0d45520
共有 3 個文件被更改,包括 30 次插入206 次删除
  1. 24 94
      gmus-mobile/lib/main.dart
  2. 4 110
      gmus-mobile/pubspec.lock
  3. 2 2
      gmus-mobile/pubspec.yaml

+ 24 - 94
gmus-mobile/lib/main.dart

@@ -1,108 +1,38 @@
 import 'package:flutter/material.dart';
-import 'package:async_redux/async_redux.dart';
+import 'package:get/get.dart';
 
-class GlobalState {
-  String name;
+void main() => runApp(GetMaterialApp(home: Gmus()));
 
-  GlobalState({
-    @required this.name,
-  });
-}
-
-class NameSetAction extends ReduxAction<GlobalState> {
-  final String newName;
-
-  NameSetAction({@required this.newName}) : assert(newName != null);
-
-  @override
-  GlobalState reduce() {
-    state.name = newName;
-    return state;
+class Controller extends GetxController {
+  var name = ''.obs;
+  setName(String newName) {
+    name.value = newName;
   }
 }
 
-GlobalState initialState = new GlobalState(
-    name: '',
-  );
-
-var store = Store<GlobalState>(initialState: initialState);
-
-void main() {
-  runApp(Gmus(store: store));
-}
-
 class Gmus extends StatelessWidget {
-  final Store<GlobalState> store;
-
-  Gmus({
-    Key key,
-    @required this.store,
-  }) : super(key: key);
-
-  @override
-  Widget build(BuildContext context) => StoreProvider<GlobalState>(
-      store: this.store,
-      child: MaterialApp(
-        title: 'gmus-mobile',
-        home: GmusConnector(),
-      ),
-  );
-}
-
-class GmusConnector extends StatelessWidget {
-  GmusConnector({Key key}) : super(key: key);
-
   @override
   Widget build(BuildContext context) {
-    return StoreConnector<GlobalState, ViewModel>(
-        vm: () => Factory(this),
-        builder: (BuildContext context, ViewModel vm) => GmusHome(
-            state: vm.state,
-            onSetName: vm.onSetName,
-          ),
-    );
-  }
-}
-
-class Factory extends VmFactory<GlobalState, GmusConnector> {
-  Factory(widget) : super(widget);
-
-  @override
-  ViewModel fromStore() => ViewModel(
-      state: state,
-      onSetName: (String newName) => dispatch(NameSetAction(newName: newName)),
-    );
-}
-
-class ViewModel extends Vm {
-  final GlobalState state;
-  final Function(String) onSetName;
+    final Controller controller = Get.put(Controller());
 
-  ViewModel({
-    @required this.state,
-    @required this.onSetName,
-  }) : super(equals: [state]);
-}
-
-class GmusHome extends StatelessWidget {
-  final GlobalState state;
-  final Function(String) onSetName;
-
-  GmusHome({
-    Key key,
-    this.state,
-    this.onSetName,
-  }) : super(key: key);
-
-  @override
-  Widget build(BuildContext context) {
     return Scaffold(
-          appBar: AppBar(
-              title: Text('gmus'),
-            ),
-          body: Center(
-              child: Text("name: ${this.state.name}"),
-            ),
+      appBar: AppBar(
+          title: Text('gmus'),
+        ),
+      body: Container(
+          child: Column(
+              children: [
+                Obx(() => Text("Name: ${controller.name}")),
+                TextField(
+                    onChanged: controller.setName,
+                    decoration: InputDecoration(
+                        border: InputBorder.none,
+                        hintText: 'Set name',
+                      ),
+                ),
+              ],
+          ),
+        ),
       );
   }
 }

+ 4 - 110
gmus-mobile/pubspec.lock

@@ -8,13 +8,6 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "2.5.0"
-  async_redux:
-    dependency: "direct main"
-    description:
-      name: async_redux
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "7.0.2"
   boolean_selector:
     dependency: transitive
     description:
@@ -64,27 +57,6 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.2.0"
-  fast_immutable_collections:
-    dependency: transitive
-    description:
-      name: fast_immutable_collections
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "1.0.28"
-  ffi:
-    dependency: transitive
-    description:
-      name: ffi
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "0.1.3"
-  file:
-    dependency: transitive
-    description:
-      name: file
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "6.0.0"
   flutter:
     dependency: "direct main"
     description: flutter
@@ -95,13 +67,13 @@ packages:
     description: flutter
     source: sdk
     version: "0.0.0"
-  logging:
-    dependency: transitive
+  get:
+    dependency: "direct main"
     description:
-      name: logging
+      name: get
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "0.11.4"
+    version: "3.25.4"
   matcher:
     dependency: transitive
     description:
@@ -123,62 +95,6 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.8.0"
-  path_provider:
-    dependency: transitive
-    description:
-      name: path_provider
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "1.6.27"
-  path_provider_linux:
-    dependency: transitive
-    description:
-      name: path_provider_linux
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "0.0.1+2"
-  path_provider_macos:
-    dependency: transitive
-    description:
-      name: path_provider_macos
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "0.0.4+8"
-  path_provider_platform_interface:
-    dependency: transitive
-    description:
-      name: path_provider_platform_interface
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "1.0.4"
-  path_provider_windows:
-    dependency: transitive
-    description:
-      name: path_provider_windows
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "0.0.4+3"
-  platform:
-    dependency: transitive
-    description:
-      name: platform
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "3.0.0"
-  plugin_platform_interface:
-    dependency: transitive
-    description:
-      name: plugin_platform_interface
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "1.0.3"
-  process:
-    dependency: transitive
-    description:
-      name: process
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "4.1.0"
   sky_engine:
     dependency: transitive
     description: flutter
@@ -240,27 +156,5 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "2.1.0"
-  weak_map:
-    dependency: transitive
-    description:
-      name: weak_map
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "1.3.1"
-  win32:
-    dependency: transitive
-    description:
-      name: win32
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "1.7.4+1"
-  xdg_directories:
-    dependency: transitive
-    description:
-      name: xdg_directories
-      url: "https://pub.dartlang.org"
-    source: hosted
-    version: "0.1.2"
 sdks:
   dart: ">=2.12.0-0.0 <3.0.0"
-  flutter: ">=1.12.13+hotfix.5"

+ 2 - 2
gmus-mobile/pubspec.yaml

@@ -18,13 +18,13 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
 version: 1.0.0+1
 
 environment:
-  sdk: ">=2.12.0 <3.0.0"
+  sdk: ">=2.7.0 <3.0.0"
 
 dependencies:
   flutter:
     sdk: flutter
 
-  async_redux: ^7.0.0
+  get: ^3.25.4
 
   # The following adds the Cupertino Icons font to your application.
   # Use with the CupertinoIcons class for iOS style icons.