Skip to content

Commit

Permalink
router and menu init
Browse files Browse the repository at this point in the history
  • Loading branch information
Predidit committed May 9, 2024
1 parent bcc31e3 commit b02c35d
Show file tree
Hide file tree
Showing 21 changed files with 1,883 additions and 193 deletions.
1 change: 1 addition & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extensions:
14 changes: 14 additions & 0 deletions lib/app_module.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/pages/index_module.dart';

class AppModule extends Module {
@override
void binds(i) {

}

@override
void routes(r) {
r.module("/", module: IndexModule());
}
}
63 changes: 63 additions & 0 deletions lib/app_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'dart:io';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';

class AppWidget extends StatefulWidget {
const AppWidget({super.key});

@override
State<AppWidget> createState() => _AppWidgetState();
}

class _AppWidgetState extends State<AppWidget> {
@override
Widget build(BuildContext context) {
var app = AdaptiveTheme(
light: ThemeData(
useMaterial3: true,
brightness: Brightness.light,
),
dark: ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
),
initial: AdaptiveThemeMode.system,
builder: (theme, darkTheme) => MaterialApp.router(
title: "Kazumi",
localizationsDelegates: GlobalMaterialLocalizations.delegates,
supportedLocales: const [
Locale.fromSubtags(
languageCode: 'zh', scriptCode: 'Hans', countryCode: "CN")
],
locale: const Locale.fromSubtags(
languageCode: 'zh', scriptCode: 'Hans', countryCode: "CN"),
theme: theme,
darkTheme: darkTheme,
routerConfig: Modular.routerConfig,
builder: FlutterSmartDialog.init(),
),
);
Modular.setObservers([FlutterSmartDialog.observer]);

// 强制设置高帧率
if (Platform.isAndroid) {
try {
late List modes;
FlutterDisplayMode.supported.then((value) {
modes = value;
DisplayMode f = DisplayMode.auto;
DisplayMode preferred = modes.toList().firstWhere((el) => el == f);
FlutterDisplayMode.setPreferredMode(preferred);
});
} catch (e) {
debugPrint('高帧率设置失败 ${e.toString()}');
}
}

return app;
}
}
152 changes: 32 additions & 120 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,125 +1,37 @@
import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
}
import 'dart:io';

class MyApp extends StatelessWidget {
const MyApp({super.key});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
import 'package:flutter/material.dart';
import 'package:kazumi/app_module.dart';
import 'package:kazumi/app_widget.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:media_kit/media_kit.dart';
// import 'package:kazumi/utils/storage.dart';
// import 'package:kazumi/request/request.dart';
import 'package:window_manager/window_manager.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
if (Platform.isWindows || Platform.isLinux) {
await windowManager.ensureInitialized();
WindowOptions windowOptions = const WindowOptions(
size: Size(1280, 830),
center: true,
// backgroundColor: Colors.white,
skipTaskbar: false,
titleBarStyle: TitleBarStyle.normal,
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.

// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
});
// windowManager.setMaximizable(false);
}

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
MediaKit.ensureInitialized();
// await GStorage.init();
// Request();
// await Request.setCookie();
runApp(ModularApp(
module: AppModule(),
child: const AppWidget(),
));
}
35 changes: 35 additions & 0 deletions lib/pages/index_module.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:kazumi/pages/index_page.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/pages/router.dart';
import 'package:kazumi/pages/init_page.dart';
import 'package:flutter/material.dart';


class IndexModule extends Module {
@override
List<Module> get imports => menu.moduleList;

@override
void binds(i) {
// i.addSingleton(PopularController.new);
}

@override
void routes(r) {
r.child("/",
child: (_) => const InitPage(),
children: [
ChildRoute(
"/error",
child: (_) => Scaffold(
appBar: AppBar (title: const Text("BiliNeo")),
body: const Center(child: Text("初始化失败")),
),
),
],
transition: TransitionType.noTransition);
r.child("/tab", child: (_) {
return const IndexPage();
}, children: menu.routes, transition: TransitionType.noTransition);
}
}
30 changes: 30 additions & 0 deletions lib/pages/index_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:flutter/material.dart';
import 'package:kazumi/pages/menu/menu.dart';


class IndexPage extends StatefulWidget {
//const IndexPage({super.key});
const IndexPage({Key? key}) : super(key: key);

@override
State<IndexPage> createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> with WidgetsBindingObserver {

final PageController _page = PageController();

/// 统一处理前后台改变
void appListener(bool state) {
if (state) {
debugPrint("应用前台");
} else {
debugPrint("应用后台");
}
}

@override
Widget build(BuildContext context) {
return const BottomMenu();
}
}
61 changes: 61 additions & 0 deletions lib/pages/init_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';

class InitPage extends StatefulWidget {
const InitPage({super.key});

@override
State<InitPage> createState() => _InitPageState();
}

class _InitPageState extends State<InitPage> {

@override
void initState() {
_init();
super.initState();
}

_init() {
Modular.to.navigate('/tab/popular/');
}

@override
Widget build(BuildContext context) {
return const RouterOutlet();
}
}

class LoadingWidget extends StatelessWidget {
const LoadingWidget({super.key, required this.value});

final double value;

@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(title: const Text("Kazumi")),
body: Center(
child: SizedBox(
height: 200,
child: Flex(
direction: Axis.vertical,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
width: size.width * 0.6,
child: LinearProgressIndicator(
value: value,
backgroundColor: Colors.black12,
minHeight: 10,
),
),
const Text("初始化中"),
],
),
),
),
);
}
}
Loading

0 comments on commit b02c35d

Please sign in to comment.