Skip to content

Commit

Permalink
updated with_go_router_example
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin-morocho committed Oct 12, 2023
1 parent 9aedca2 commit fba9576
Show file tree
Hide file tree
Showing 20 changed files with 175 additions and 212 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ jobs:
- name: Install meedu dependencies
run: cd packages/meedu && flutter pub get

- name: Run meedu tests
run: cd packages/meedu && flutter test --coverage


- name: Install flutter_meedu dependencies
run: cd packages/flutter_meedu && flutter pub get

Expand Down
2 changes: 1 addition & 1 deletion examples/with_go_router/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
13 changes: 8 additions & 5 deletions examples/with_go_router/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -127,7 +127,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -171,10 +171,12 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand All @@ -185,6 +187,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -272,7 +275,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -350,7 +353,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -399,7 +402,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 4 additions & 0 deletions examples/with_go_router/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,9 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
7 changes: 3 additions & 4 deletions examples/with_go_router/lib/app/my_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:flutter/material.dart';

import 'ui/routes/app_routes.dart';

class MyApp extends StatelessWidget with AppRoutesMixin {
MyApp({Key? key}) : super(key: key);
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -12,8 +12,7 @@ class MyApp extends StatelessWidget with AppRoutesMixin {
theme: ThemeData(
primarySwatch: Colors.blue,
),
routeInformationParser: goRouter.routeInformationParser,
routerDelegate: goRouter.routerDelegate,
routerConfig: routerProvider.read(),
);
}
}

This file was deleted.

10 changes: 10 additions & 0 deletions examples/with_go_router/lib/app/ui/pages/color/color_notifier.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:flutter_meedu/notifiers.dart';
import 'package:flutter_meedu/providers.dart';

final colorProvider = StateNotifierArgumentsProvider<ColorNotifier, int, int>(
(ref) => ColorNotifier(ref.arguments),
);

class ColorNotifier extends StateNotifier<int> {
ColorNotifier(super.initialState);
}
13 changes: 7 additions & 6 deletions examples/with_go_router/lib/app/ui/pages/color/color_page.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import 'package:flutter/material.dart';
import 'package:with_go_router/app/ui/pages/color/color_controller.dart';
import 'package:with_go_router/app/ui/pages/color/color_notifier.dart';

class ColorPage extends StatelessWidget {
final bool isPrimary;
final int colorIndex;
final String tagName;
ColorPage({
Key? key,
super.key,
required this.isPrimary,
required this.colorIndex,
}) : tagName = '$isPrimary-$colorIndex',
super(key: key) {
}) : tagName = '$isPrimary-$colorIndex'{

print(tagName);
colorProvider.setArguments(
tagName,
colorIndex,
tag: tagName,
);
}

@override
Widget build(BuildContext context) {
final index = colorProvider.find(tagName).read.color;
final index = colorProvider.read(tag: tagName).state;
return Scaffold(
appBar: AppBar(),
body: Container(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter_meedu/notifiers.dart';
import 'package:flutter_meedu/providers.dart';

final counterProvider = StateNotifierProvider<CounterNotifier, int>(
(_) => CounterNotifier(0),
);

class CounterNotifier extends StateNotifier<int> {
CounterNotifier(super.initialState);

void increment() {
state++;
}

@override
void dispose() {
print("counter disposed");
super.dispose();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_meedu/ui.dart';
import 'package:flutter_meedu/consumer.dart';

import 'controller/counter_provider.dart';
import 'controller/counter_notifier.dart';

class CounterPage extends StatelessWidget {
const CounterPage({Key? key}) : super(key: key);
Expand All @@ -13,17 +13,17 @@ class CounterPage extends StatelessWidget {
body: Center(
child: Consumer(
builder: (_, ref, __) {
final controller = ref.watch(counterProvider);
final counter = ref.watch(counterProvider).state;
return Text(
"${controller.counter}",
"$counter",
style: const TextStyle(fontSize: 30),
);
},
),
),
floatingActionButton: FloatingActionButton(
onPressed: counterProvider.read().increment,
child: const Icon(Icons.add),
onPressed: counterProvider.read.increment,
),
);
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:with_go_router/app/ui/pages/nested/tabs/accents_colors.dart';
import 'package:with_go_router/app/ui/pages/nested/tabs/primaries_colors.dart';
import 'package:with_go_router/app/ui/routes/routes.dart';

import 'tabs/accents_colors.dart';
import 'tabs/primaries_colors.dart';

class NestedPage extends StatefulWidget {
final int index;
const NestedPage({
Expand Down Expand Up @@ -67,6 +68,7 @@ class _NestedPageState extends State<NestedPage> with TickerProviderStateMixin {
),
),
body: TabBarView(
controller: _controller,
children: const [
PrimariesColors(
tabIndex: 0,
Expand All @@ -75,7 +77,6 @@ class _NestedPageState extends State<NestedPage> with TickerProviderStateMixin {
tabIndex: 1,
),
],
controller: _controller,
),
);
}
Expand Down
22 changes: 9 additions & 13 deletions examples/with_go_router/lib/app/ui/routes/app_routes.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import 'package:flutter/widgets.dart' show StatelessWidget;
import 'package:flutter_meedu/ui.dart';
import 'package:flutter_meedu/flutter_meedu.dart';
import 'package:go_router/go_router.dart';
import 'package:with_go_router/app/ui/pages/color/color_page.dart';
import 'package:with_go_router/app/ui/pages/home/home_page.dart';
import 'package:with_go_router/app/ui/pages/nested/nested_page.dart';
import 'package:with_go_router/app/ui/routes/routes.dart';

import '../pages/counter/counter_page.dart';
import '../pages/nested/nested_page.dart';

mixin AppRoutesMixin on StatelessWidget {
final goRouter = GoRouter(
final routerProvider = Provider(
(ref) => GoRouter(
routes: [
GoRoute(
path: '/',
Expand All @@ -22,14 +21,14 @@ mixin AppRoutesMixin on StatelessWidget {
GoRoute(
path: "${Routes.NESTED}/:index",
builder: (_, state) => NestedPage(
index: int.tryParse(state.params['index'] ?? '0') ?? 0,
index: int.tryParse(state.pathParameters['index'] ?? '0') ?? 0,
),
routes: [
GoRoute(
path: 'primaries/:color',
builder: (_, state) {
final colorIndex = int.tryParse(
state.params['color'] ?? '0',
state.pathParameters['color'] ?? '0',
) ??
0;
return ColorPage(
Expand All @@ -42,7 +41,7 @@ mixin AppRoutesMixin on StatelessWidget {
path: 'accents/:color',
builder: (_, state) {
final colorIndex = int.tryParse(
state.params['color'] ?? '0',
state.pathParameters['color'] ?? '0',
) ??
0;
return ColorPage(
Expand All @@ -54,8 +53,5 @@ mixin AppRoutesMixin on StatelessWidget {
],
),
],
observers: [
router.observer,
],
);
}
),
);
4 changes: 3 additions & 1 deletion examples/with_go_router/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ import 'package:flutter/material.dart';
import 'app/my_app.dart';

void main() {
runApp(MyApp());
runApp(
const MyApp(),
);
}
Loading

0 comments on commit fba9576

Please sign in to comment.