Browse Source

para los routes

Oniel Mendez 4 years ago
parent
commit
2b30ae2c54

+ 3
- 0
fast_med_flutter/android/app/src/main/AndroidManifest.xml View File

@@ -5,6 +5,9 @@
5 5
          In most cases you can leave this as-is, but you if you want to provide
6 6
          additional functionality it is fine to subclass or reimplement
7 7
          FlutterApplication and put your custom class here. -->
8
+    <!-- Required to fetch data from the internet. -->
9
+    <uses-permission android:name="android.permission.INTERNET" />
10
+
8 11
     <application
9 12
         android:name="io.flutter.app.FlutterApplication"
10 13
         android:label="fast_med_flutter"

+ 9
- 115
fast_med_flutter/lib/main.dart View File

@@ -1,117 +1,11 @@
1
+import 'package:fast_med_flutter/routes/home.dart';
2
+import 'package:fast_med_flutter/routes/ver_oficinas.dart';
1 3
 import 'package:flutter/material.dart';
2 4
 
3
-void main() {
4
-  runApp(MyApp());
5
-}
6
-
7
-class MyApp extends StatelessWidget {
8
-  // This widget is the root of your application.
9
-  @override
10
-  Widget build(BuildContext context) {
11
-    return MaterialApp(
12
-      title: 'Flutter Demo',
13
-      theme: ThemeData(
14
-        // This is the theme of your application.
15
-        //
16
-        // Try running your application with "flutter run". You'll see the
17
-        // application has a blue toolbar. Then, without quitting the app, try
18
-        // changing the primarySwatch below to Colors.green and then invoke
19
-        // "hot reload" (press "r" in the console where you ran "flutter run",
20
-        // or simply save your changes to "hot reload" in a Flutter IDE).
21
-        // Notice that the counter didn't reset back to zero; the application
22
-        // is not restarted.
23
-        primarySwatch: Colors.blue,
24
-        // This makes the visual density adapt to the platform that you run
25
-        // the app on. For desktop platforms, the controls will be smaller and
26
-        // closer together (more dense) than on mobile platforms.
27
-        visualDensity: VisualDensity.adaptivePlatformDensity,
28
-      ),
29
-      home: MyHomePage(title: 'Flutter Demo Home Page'),
30
-    );
31
-  }
32
-}
33
-
34
-class MyHomePage extends StatefulWidget {
35
-  MyHomePage({Key key, this.title}) : super(key: key);
36
-
37
-  // This widget is the home page of your application. It is stateful, meaning
38
-  // that it has a State object (defined below) that contains fields that affect
39
-  // how it looks.
40
-
41
-  // This class is the configuration for the state. It holds the values (in this
42
-  // case the title) provided by the parent (in this case the App widget) and
43
-  // used by the build method of the State. Fields in a Widget subclass are
44
-  // always marked "final".
45
-
46
-  final String title;
47
-
48
-  @override
49
-  _MyHomePageState createState() => _MyHomePageState();
50
-}
51
-
52
-class _MyHomePageState extends State<MyHomePage> {
53
-  int _counter = 0;
54
-
55
-  void _incrementCounter() {
56
-    setState(() {
57
-      // This call to setState tells the Flutter framework that something has
58
-      // changed in this State, which causes it to rerun the build method below
59
-      // so that the display can reflect the updated values. If we changed
60
-      // _counter without calling setState(), then the build method would not be
61
-      // called again, and so nothing would appear to happen.
62
-      _counter++;
63
-    });
64
-  }
65
-
66
-  @override
67
-  Widget build(BuildContext context) {
68
-    // This method is rerun every time setState is called, for instance as done
69
-    // by the _incrementCounter method above.
70
-    //
71
-    // The Flutter framework has been optimized to make rerunning build methods
72
-    // fast, so that you can just rebuild anything that needs updating rather
73
-    // than having to individually change instances of widgets.
74
-    return Scaffold(
75
-      appBar: AppBar(
76
-        // Here we take the value from the MyHomePage object that was created by
77
-        // the App.build method, and use it to set our appbar title.
78
-        title: Text(widget.title),
79
-      ),
80
-      body: Center(
81
-        // Center is a layout widget. It takes a single child and positions it
82
-        // in the middle of the parent.
83
-        child: Column(
84
-          // Column is also a layout widget. It takes a list of children and
85
-          // arranges them vertically. By default, it sizes itself to fit its
86
-          // children horizontally, and tries to be as tall as its parent.
87
-          //
88
-          // Invoke "debug painting" (press "p" in the console, choose the
89
-          // "Toggle Debug Paint" action from the Flutter Inspector in Android
90
-          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
91
-          // to see the wireframe for each widget.
92
-          //
93
-          // Column has various properties to control how it sizes itself and
94
-          // how it positions its children. Here we use mainAxisAlignment to
95
-          // center the children vertically; the main axis here is the vertical
96
-          // axis because Columns are vertical (the cross axis would be
97
-          // horizontal).
98
-          mainAxisAlignment: MainAxisAlignment.center,
99
-          children: <Widget>[
100
-            Text(
101
-              'You have pushed the button this many times:',
102
-            ),
103
-            Text(
104
-              '$_counter',
105
-              style: Theme.of(context).textTheme.headline4,
106
-            ),
107
-          ],
108
-        ),
109
-      ),
110
-      floatingActionButton: FloatingActionButton(
111
-        onPressed: _incrementCounter,
112
-        tooltip: 'Increment',
113
-        child: Icon(Icons.add),
114
-      ), // This trailing comma makes auto-formatting nicer for build methods.
115
-    );
116
-  }
117
-}
5
+void main() => runApp(MaterialApp(
6
+    initialRoute: '/home',
7
+    routes: {
8
+      '/home': (context) => Home(),
9
+      '/verOficinas': (context) => VerOficinas(),
10
+    }
11
+));

+ 31
- 0
fast_med_flutter/lib/routes/home.dart View File

@@ -0,0 +1,31 @@
1
+import 'package:flutter/material.dart';
2
+
3
+class Home extends StatefulWidget{
4
+  @override
5
+  _HomeState createState() => _HomeState();
6
+}
7
+
8
+class _HomeState extends State<Home>{
9
+  @override
10
+  Widget build(BuildContext context){
11
+    return Scaffold(
12
+      appBar: AppBar(
13
+        title: Text('Bienvenido'),
14
+        centerTitle: true,
15
+      ),
16
+      body: Center(
17
+          child: FlatButton(
18
+            minWidth: 300.0,
19
+            height: 100.0,
20
+            onPressed: (){
21
+              Navigator.pushNamed(context, '/verOficinas');
22
+            },
23
+            child: Text('Ver Oficinas'),
24
+            color: Colors.purple,
25
+
26
+          )
27
+      ),
28
+
29
+    );
30
+  }
31
+}

+ 91
- 0
fast_med_flutter/lib/routes/ver_oficinas.dart View File

@@ -0,0 +1,91 @@
1
+import 'package:flutter/material.dart';
2
+import '../widgets/DataTableMySqlDemo/Oficina.dart';
3
+import '../widgets/DataTableMySqlDemo/Services.dart';
4
+import 'dart:async';
5
+
6
+class VerOficinas extends StatefulWidget{
7
+  VerOficinas() : super();
8
+  final String title = 'Oficinas';
9
+  @override
10
+  State<StatefulWidget> viewOficinas() {
11
+    //no se que hago, quizas no lo necesite
12
+    return null;
13
+  }
14
+  _VerOficinasState createState() => _VerOficinasState();
15
+}
16
+
17
+class _VerOficinasState extends State<VerOficinas>{
18
+  List<Oficina> _oficinas;
19
+  List<Oficina> _filterOficinas;
20
+  GlobalKey<ScaffoldState> _scaffoldKey;
21
+  TextEditingController _nameController;//
22
+  Oficina _selectOficina;
23
+  bool _isUpdateing;
24
+
25
+  @override
26
+  void initState() {
27
+    super.initState();
28
+    _oficinas = [];
29
+    // _filterOficinas = [];
30
+    _isUpdateing = false;
31
+    _scaffoldKey = GlobalKey();
32
+    _nameController = TextEditingController();
33
+    _getOficinas();
34
+  }
35
+
36
+  _getOficinas() {
37
+
38
+    return _oficinas;
39
+  }
40
+
41
+
42
+  @override
43
+  Widget build(BuildContext context){
44
+    Services.getOficinas().then((Oficinas) {
45
+      setState(() {
46
+        _oficinas = Oficinas;
47
+        print(_oficinas);
48
+        print("Length ${Oficinas.length}");
49
+      });
50
+
51
+    });
52
+    List<Oficina> lista =  _oficinas;
53
+    return Scaffold(
54
+      key: _scaffoldKey,
55
+      appBar: AppBar(
56
+        title: Text('Oficinas'),
57
+        centerTitle: true,
58
+        backgroundColor: Colors.purple,
59
+
60
+      ),
61
+      body: Center(
62
+          child: Column(
63
+            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
64
+            children: lista.map((Oficina data) {
65
+              return FlatButton(
66
+                minWidth: 300.0,
67
+                height: 100.0,
68
+                child: Text(data.name,
69
+                style: TextStyle(fontSize: 36),
70
+                ),
71
+                onPressed: () {
72
+                  print(data.name);
73
+                },
74
+                padding: new EdgeInsets.all(0.0),
75
+                color: Colors.purple,
76
+
77
+              );
78
+            }).toList(),
79
+          ),
80
+          // child: FlatButton(
81
+          //   onPressed: (){
82
+          //     _getOficinas();
83
+          //   },
84
+          //   child: Text('Ver Oficinas'),
85
+          //   color: Colors.purple,
86
+          // )
87
+      ),
88
+
89
+    );
90
+  }
91
+}

+ 13
- 0
fast_med_flutter/lib/widgets/DataTableMySqlDemo/Oficina.dart View File

@@ -0,0 +1,13 @@
1
+class Oficina {
2
+  String id;
3
+  String name;
4
+
5
+  Oficina({this.id, this.name});
6
+
7
+  factory Oficina.fromJson(Map<String, dynamic> json) {
8
+    return Oficina (
9
+      id :json['id'] as String,
10
+      name: json['name'] as String,
11
+    );
12
+  }
13
+}

+ 46
- 0
fast_med_flutter/lib/widgets/DataTableMySqlDemo/Services.dart View File

@@ -0,0 +1,46 @@
1
+import 'dart:convert';
2
+import 'package:http/http.dart'
3
+  as http;
4
+import 'Oficina.dart';
5
+
6
+class Services {
7
+  static const URL = 'https://ada.uprrp.edu/~oniel.mendez2/json/oficinas.php';
8
+  static const URL_GET_ALL = 'ada.uprrp.edu/~oniel.mendez2/json/getOficinas.php';
9
+  static const URL_LOCAL = 'http://localhost/test/getOficinas.json';
10
+  static const _GET_ALL = "GET_ALL";
11
+
12
+  //get all oficinas
13
+  static Future<List<Oficina>> getOficinas() async {
14
+    try {
15
+      var map = Map<String, dynamic>();
16
+      map['action'] = _GET_ALL;
17
+      print('antes');
18
+      // final response = await http.get(URL_GET_ALL);
19
+      // print('despues');
20
+      // print('getOficinas Response: ${response.body}');
21
+      // if (200 == response.statusCode) {
22
+      //   List<Oficina> list = parseResponse(response.body);
23
+      final response = '[{"id":"1","name":"test1"},{"id":"2","name":"test2"},{"id":"3","name":"test3"}]';
24
+      print('despues');
25
+      print('getOficinas Response: $response');
26
+      if (200 == 200) {
27
+        List<Oficina> list = parseResponse(response);
28
+        return list;
29
+      } else {
30
+        return List<Oficina>();
31
+      }
32
+    } catch (e) {
33
+      return List<Oficina>(); // return an empty list on exception/error
34
+    }
35
+  }
36
+
37
+  static List<Oficina> parseResponse(String responseBody) {
38
+    final parsed = json.decode(responseBody).cast<Map<String, dynamic>>();
39
+    return parsed.map<Oficina>((json) => Oficina.fromJson(json)).toList();
40
+  }
41
+
42
+  Future<http.Response> fetchAlbum() {
43
+    return http.get('https://jsonplaceholder.typicode.com/albums/1');
44
+  }
45
+
46
+}

+ 1
- 0
fast_med_flutter/lib/widgets/MySQL_DataTable/dud.dart View File

@@ -0,0 +1 @@
1
+import 'dart:convert';

+ 0
- 0
fast_med_flutter/lib/widgets/data_table/dud.dart View File


+ 1
- 0
fast_med_flutter/lib/widgets/dud.dart View File

@@ -0,0 +1 @@
1
+import 'dart:convert';

+ 21
- 0
fast_med_flutter/pubspec.lock View File

@@ -67,6 +67,20 @@ packages:
67 67
     description: flutter
68 68
     source: sdk
69 69
     version: "0.0.0"
70
+  http:
71
+    dependency: "direct main"
72
+    description:
73
+      name: http
74
+      url: "https://pub.dartlang.org"
75
+    source: hosted
76
+    version: "0.12.2"
77
+  http_parser:
78
+    dependency: transitive
79
+    description:
80
+      name: http_parser
81
+      url: "https://pub.dartlang.org"
82
+    source: hosted
83
+    version: "3.1.4"
70 84
   matcher:
71 85
     dependency: transitive
72 86
     description:
@@ -88,6 +102,13 @@ packages:
88 102
       url: "https://pub.dartlang.org"
89 103
     source: hosted
90 104
     version: "1.8.0-nullsafety.1"
105
+  pedantic:
106
+    dependency: transitive
107
+    description:
108
+      name: pedantic
109
+      url: "https://pub.dartlang.org"
110
+    source: hosted
111
+    version: "1.9.2"
91 112
   sky_engine:
92 113
     dependency: transitive
93 114
     description: flutter

+ 3
- 0
fast_med_flutter/pubspec.yaml View File

@@ -29,6 +29,9 @@ dependencies:
29 29
   # Use with the CupertinoIcons class for iOS style icons.
30 30
   cupertino_icons: ^1.0.0
31 31
 
32
+  #
33
+  http: ^0.12.2
34
+
32 35
 dev_dependencies:
33 36
   flutter_test:
34 37
     sdk: flutter

+ 1
- 1
fast_med_flutter/test/widget_test.dart View File

@@ -13,7 +13,7 @@ import 'package:fast_med_flutter/main.dart';
13 13
 void main() {
14 14
   testWidgets('Counter increments smoke test', (WidgetTester tester) async {
15 15
     // Build our app and trigger a frame.
16
-    await tester.pumpWidget(MyApp());
16
+    await tester.pumpWidget(MaterialApp());
17 17
 
18 18
     // Verify that our counter starts at 0.
19 19
     expect(find.text('0'), findsOneWidget);