Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add example with simple onGenerateRoute navigation #206

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main() {
win.minSize = initialSize;
win.size = initialSize;
win.alignment = Alignment.center;
win.title = "Custom window with Flutter";
win.title = "Custom Window With No Navigation Flutter";
win.show();
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:flutter/material.dart';

import 'routes.dart';
import 'title_bar.dart';

void main() {
runApp(const MyApp());
doWhenWindowReady(() {
final win = appWindow;
const initialSize = Size(600, 450);
win.minSize = initialSize;
win.size = initialSize;
win.alignment = Alignment.center;
win.title = "Simple Window With OnGenerate Route";
win.show();
});
}

class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);

@override
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
//
// Router
final AppRouter router = AppRouter();

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
builder: (context, child) {
//
return ExamplWithOnGenerateRouteTitleBar(
child: Navigator(
initialRoute: Routes.screenOne,
onGenerateRoute: router.onGenerateRoute,
),
);
},
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:animations/animations.dart';
import 'package:flutter/material.dart';

import 'screen_one.dart';
import 'screen_three.dart';
import 'screen_two.dart';

class Routes {
//
static const String screenOne = 'screen-one';
static const String screenTwo = 'screen-two';
static const String screenThree = 'screen-three';
//
static Route<T> fadeThrough<T>(RouteSettings settings, WidgetBuilder page,
{int duration = 500}) {
return PageRouteBuilder<T>(
settings: settings,
transitionDuration: Duration(milliseconds: duration),
pageBuilder: (context, animation, secondaryAnimation) => page(context),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
return FadeScaleTransition(animation: animation, child: child);
},
);
}
//
}

class AppRouter {
//
Route onGenerateRoute(RouteSettings settings) {
//
return Routes.fadeThrough(settings, (context) {
//
switch (settings.name) {
case Routes.screenOne:
return const ScreenOne();

case Routes.screenTwo:
return const ScreenTwo();

case Routes.screenThree:
return const ScreenThree();

default:
return const SizedBox.shrink();
}
//
});
//
}
//
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:flutter/material.dart';

import 'routes.dart';

class ScreenOne extends StatefulWidget {
const ScreenOne({Key? key}) : super(key: key);

@override
State<ScreenOne> createState() => _ScreenOneState();
}

class _ScreenOneState extends State<ScreenOne> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//
Text(
"This is screen one",
style: Theme.of(context).textTheme.headlineMedium,
),

const SizedBox(height: 20),

ElevatedButton(
onPressed: () => Navigator.pushNamed(context, Routes.screenTwo),
child: const Text("Go To Screen Two"),
)
//
],
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:flutter/material.dart';

import 'routes.dart';

class ScreenThree extends StatefulWidget {
const ScreenThree({Key? key}) : super(key: key);

@override
State<ScreenThree> createState() => _ScreenThreeState();
}

class _ScreenThreeState extends State<ScreenThree> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//
Text(
"This is screen three",
style: Theme.of(context).textTheme.headlineMedium,
),

const SizedBox(height: 20),

ElevatedButton(
onPressed: () => Navigator.pushNamed(context, Routes.screenOne),
child: const Text("Go Back To Screen One"),
)
//
],
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:flutter/material.dart';

import 'routes.dart';

class ScreenTwo extends StatefulWidget {
const ScreenTwo({Key? key}) : super(key: key);

@override
State<ScreenTwo> createState() => _ScreenTwoState();
}

class _ScreenTwoState extends State<ScreenTwo> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//
Text(
"This is screen two",
style: Theme.of(context).textTheme.headlineMedium,
),

const SizedBox(height: 20),

ElevatedButton(
onPressed: () => Navigator.pushNamed(context, Routes.screenThree),
child: const Text("Go To Screen Three"),
)
//
],
),
),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:flutter/material.dart';

class ExamplWithOnGenerateRouteTitleBar extends StatelessWidget {
const ExamplWithOnGenerateRouteTitleBar({
Key? key,
required this.child,
}) : super(key: key);

final Widget child;

@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
//
WindowTitleBarBox(
child: MoveWindow(
child: Container(
color: Colors.deepOrange, // Enter any color you prefer
child: Row(
children: const [
//
Padding(
padding: EdgeInsets.only(left: 10),
child: Text(
"App With Simple OnGenerateRoute Navigation",
style: TextStyle(
fontSize: 12,
color: Colors.white,
),
),
),

Spacer(),

ActionButtons()
//
],
),
),
),
),

Flexible(child: child)
//
],
),
);
}
}

class ActionButtons extends StatelessWidget {
const ActionButtons({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Row(
children: [
//
MinimizeWindowButton(
animate: false,
colors: WindowButtonColors(
iconNormal: Colors.white,
),
),
MaximizeWindowButton(
animate: false,
colors: WindowButtonColors(
iconNormal: Colors.white,
),
),
CloseWindowButton(
animate: false,
colors: WindowButtonColors(
iconNormal: Colors.white,
),
),
//
],
);
}
}
1 change: 1 addition & 0 deletions bitsdojo_window/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.1
animations: ^2.0.7

dev_dependencies:
flutter_test:
Expand Down