feat: 主页面功能
This commit is contained in:
1 parent
91edb73885
commit
f233f1c642
21 files changed
+1295
-104
No files matched your search
@@ -0,0 +1,19 @@
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
class ConstColor {
|
||||
|
||||
// #100C08
|
||||
static Color themeColor = Color(0xff100C08);
|
||||
// #EEEEEE
|
||||
static Color btWhite = Color(0xffEEEEEE);
|
||||
// #89F011
|
||||
static Color btGreen = Color(0xff89F011);
|
||||
|
||||
static Color withValue(String value) {
|
||||
String colorValue = value.replaceAll('#', '');
|
||||
String res = '0xff$colorValue';
|
||||
int valueInt = int.parse(res);
|
||||
return Color(valueInt);
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,117 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// navigator
|
||||
class AppNav {
|
||||
/// clear all route
|
||||
static Future<T?>? offAllNamed<T>(
|
||||
String newRouteName, {
|
||||
Map? arguments,
|
||||
RoutePredicate? predicate,
|
||||
String? tag,
|
||||
Map? parameters,
|
||||
}) {
|
||||
return Get.offAllNamed<T>(
|
||||
newRouteName,
|
||||
arguments: arguments,
|
||||
predicate: predicate,
|
||||
parameters: {...?parameters},
|
||||
);
|
||||
}
|
||||
|
||||
static Future<T?>? off<T>(Widget page, {arguments, preventDuplicates}) {
|
||||
return Get.off<T>(
|
||||
() => page,
|
||||
arguments: arguments,
|
||||
preventDuplicates: preventDuplicates ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<T?>? offAll<T>(Widget page, {arguments, preventDuplicates}) {
|
||||
return Get.offAll<T>(() => page, arguments: arguments);
|
||||
}
|
||||
|
||||
static Future<T?>? offNamed<T>(
|
||||
String newRouteName, {
|
||||
arguments,
|
||||
preventDuplicates,
|
||||
}) {
|
||||
return Get.offNamed<T>(
|
||||
newRouteName,
|
||||
arguments: arguments,
|
||||
preventDuplicates: preventDuplicates ?? true,
|
||||
);
|
||||
}
|
||||
|
||||
/// to name
|
||||
static Future<T?>? toNamed<T>(
|
||||
String newRouteName, {
|
||||
arguments,
|
||||
String? tag,
|
||||
Map? parameters,
|
||||
}) {
|
||||
return Get.toNamed<T>(
|
||||
newRouteName,
|
||||
arguments: arguments,
|
||||
parameters: {...?parameters},
|
||||
);
|
||||
}
|
||||
|
||||
/// to route
|
||||
static Future<T?>? to<T>(Widget page, {arguments, binding}) {
|
||||
return Get.to<T>(
|
||||
() => page,
|
||||
arguments: arguments,
|
||||
binding: binding,
|
||||
preventDuplicates: false,
|
||||
);
|
||||
}
|
||||
|
||||
static void _until<T>({String? routeName, T? result}) {
|
||||
if (result == null) {
|
||||
Get.back<T>(result: result);
|
||||
return;
|
||||
}
|
||||
// Get.back<T>(result: result);
|
||||
//
|
||||
if (routeName == null) {
|
||||
Get.back<T>(result: result);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// back pre
|
||||
/// [result]
|
||||
static void back<T>({T? result, String? routeName}) {
|
||||
_until(routeName: routeName, result: result);
|
||||
}
|
||||
|
||||
/// show dialog
|
||||
static Future<T?> showDialog<T>(
|
||||
Widget child, {
|
||||
bool barrierDismissible = false,
|
||||
}) {
|
||||
return Get.dialog<T>(
|
||||
Center(child: child),
|
||||
barrierDismissible: barrierDismissible,
|
||||
);
|
||||
}
|
||||
|
||||
/// show bottom sheet
|
||||
static Future<T?> showBottom<T>(
|
||||
Widget child, {
|
||||
Color? safeAreaColor,
|
||||
|
||||
double? borderRadius,
|
||||
bool isDismissible = false,
|
||||
bool isScrollControlled = false,
|
||||
bool? enableDrag,
|
||||
}) {
|
||||
return Get.bottomSheet<T>(
|
||||
child,
|
||||
isScrollControlled: isScrollControlled,
|
||||
enableDrag: enableDrag ?? true,
|
||||
isDismissible: isDismissible,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ConstImage {
|
||||
ConstImage._();
|
||||
|
||||
/// main
|
||||
static const String appBottom = "assets/main/app_bottom.png";
|
||||
static const String pageBg = "assets/main/page_bg.png";
|
||||
static const String btHomeUnsel = "assets/main/bt_home_unsel.png";
|
||||
static const String btPlayUnsel = "assets/main/bt_play_unsel.png";
|
||||
static const String btCollectUnsel = "assets/main/bt_collect_unsel.png";
|
||||
static const String btMineUnsel = "assets/main/bt_mine_unsel.png";
|
||||
static const String btHomeSel = "assets/main/bt_home_seled.png";
|
||||
static const String btPlaySel = "assets/main/bt_play_seled.png";
|
||||
static const String btCollectSel = "assets/main/bt_collect_seled.png";
|
||||
static const String btMineSel = "assets/main/bt_mine_seled.png";
|
||||
static const String spaceImg = "assets/main/space_img.png";
|
||||
|
||||
|
||||
}
|
||||
|
||||
class HelpImage {
|
||||
static Widget asset(
|
||||
String path, {
|
||||
BoxFit? fit,
|
||||
double? width,
|
||||
double? height,
|
||||
Color? color,
|
||||
bool isDartData = false,
|
||||
String? dartPath,
|
||||
}) {
|
||||
|
||||
return Image.asset(
|
||||
path,
|
||||
fit: fit,
|
||||
width: width,
|
||||
height: height,
|
||||
color: color,
|
||||
);
|
||||
}
|
||||
|
||||
static Widget networkRadius(
|
||||
String path, {
|
||||
BoxFit? fit,
|
||||
double? width,
|
||||
double? height,
|
||||
BoxShape? shape,
|
||||
BorderRadius? borderRadius,
|
||||
Widget? errorWidget,
|
||||
}) {
|
||||
return ClipRRect(
|
||||
borderRadius: borderRadius ?? BorderRadius.circular(3),
|
||||
child: network(
|
||||
path,
|
||||
fit: fit,
|
||||
width: width,
|
||||
height: height,
|
||||
shape: shape,
|
||||
errorWidget: errorWidget,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// load network
|
||||
static Widget network(
|
||||
String path, {
|
||||
BoxFit? fit,
|
||||
double? width,
|
||||
double? height,
|
||||
Color? color,
|
||||
BoxShape? shape,
|
||||
BorderRadius? borderRadius,
|
||||
Widget? errorWidget,
|
||||
}) {
|
||||
|
||||
return FadeInImage.assetNetwork(
|
||||
placeholder: ConstImage.spaceImg,
|
||||
image: path,
|
||||
width: width, height: height, fit: BoxFit.cover,
|
||||
imageErrorBuilder: (context, error, stackTrace) {
|
||||
return asset(
|
||||
ConstImage.spaceImg,
|
||||
fit: BoxFit.fill,
|
||||
width: width, height: height
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
+138
-104
@@ -1,9 +1,145 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:novyronst/root/lib_export.dart';
|
||||
import 'package:novyronst/root/root_page.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
runApp(const RootApp());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class RootApp extends StatefulWidget {
|
||||
const RootApp({
|
||||
super.key,
|
||||
this.home,
|
||||
this.locale
|
||||
});
|
||||
|
||||
final Widget? home;
|
||||
final Locale? locale;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _RootAppState();
|
||||
}
|
||||
}
|
||||
|
||||
class _RootAppState extends State<RootApp> with WidgetsBindingObserver {
|
||||
|
||||
bool _appInForeground = true; //
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ScreenUtilInit(
|
||||
designSize: Size(375, 812),
|
||||
child: GetMaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
// translations: AppLanguage(),
|
||||
locale: widget.locale ?? Get.deviceLocale,
|
||||
fallbackLocale: const Locale('en'),
|
||||
initialBinding: AppBindings(),
|
||||
// initialRoute: SkyPages.initial,
|
||||
// getPages: SkyPages.routes,
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: ConstColor.themeColor,
|
||||
),
|
||||
appBarTheme: AppBarTheme(elevation: 0, centerTitle: true),
|
||||
splashColor: Colors.transparent,
|
||||
useMaterial3: true,
|
||||
scaffoldBackgroundColor: Colors.white,
|
||||
),
|
||||
builder: FlutterSmartDialog.init(
|
||||
builder: (context, child) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(1.0)),
|
||||
child: child!,
|
||||
);
|
||||
},
|
||||
),
|
||||
home: widget.home ?? RootPage(),
|
||||
onInit: () {},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
// _startPeriodicOnlineReport();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
super.didChangeAppLifecycleState(state);
|
||||
|
||||
switch (state) {
|
||||
case AppLifecycleState.inactive:
|
||||
case AppLifecycleState.paused:
|
||||
// 应用进入后台或不活跃状态
|
||||
if (_appInForeground) {
|
||||
print('💛应用不活跃');
|
||||
_appInForeground = false;
|
||||
_onAppPaused();
|
||||
}
|
||||
break;
|
||||
case AppLifecycleState.resumed:
|
||||
// 应用回到前台
|
||||
if (!_appInForeground) {
|
||||
print('💚应用活跃');
|
||||
_appInForeground = true;
|
||||
_onAppResumed();
|
||||
}
|
||||
break;
|
||||
case AppLifecycleState.detached:
|
||||
case AppLifecycleState.hidden:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 应用进入后台时的处理
|
||||
void _onAppPaused() {
|
||||
try {
|
||||
// EventClient.eventOLeaveApp();
|
||||
} catch (err) { print(err.toString()); }
|
||||
}
|
||||
|
||||
/// 应用回到前台时的处理
|
||||
void _onAppResumed() {
|
||||
try {
|
||||
// EventClient.eventEnterApp();
|
||||
// EventClient.eventOnline();
|
||||
} catch (err) { print(err.toString()); }
|
||||
}
|
||||
}
|
||||
|
||||
class AppBindings extends Bindings {
|
||||
|
||||
@override
|
||||
void dependencies() {
|
||||
// Get.lazyPut(() => UserController());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@@ -13,110 +149,8 @@ class MyApp extends StatelessWidget {
|
||||
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: .fromSeed(seedColor: Colors.deepPurple),
|
||||
),
|
||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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++;
|
||||
});
|
||||
}
|
||||
|
||||
@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: .center,
|
||||
children: [
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CollectionPage extends StatefulWidget {
|
||||
const CollectionPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _RootPageState();
|
||||
}
|
||||
}
|
||||
|
||||
class _RootPageState extends State<CollectionPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class FirstPage extends StatefulWidget {
|
||||
const FirstPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _RootPageState();
|
||||
}
|
||||
}
|
||||
|
||||
class _RootPageState extends State<FirstPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MyPage extends StatefulWidget {
|
||||
const MyPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _RootPageState();
|
||||
}
|
||||
}
|
||||
|
||||
class _RootPageState extends State<MyPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PlayPage extends StatefulWidget {
|
||||
const PlayPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _RootPageState();
|
||||
}
|
||||
}
|
||||
|
||||
class _RootPageState extends State<PlayPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
export 'package:novyronst/common/const/const_color.dart';
|
||||
export 'package:novyronst/common/const/const_string.dart';
|
||||
export 'package:novyronst/common/help/help_image.dart';
|
||||
|
||||
|
||||
export 'package:novyronst/tools/util/app_screen.dart';
|
||||
@@ -0,0 +1,135 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:novyronst/common/help/help_image.dart';
|
||||
import 'package:novyronst/pages/collect/pages/collection_page.dart';
|
||||
import 'package:novyronst/pages/first/pages/first_page.dart';
|
||||
import 'package:novyronst/pages/my/pages/my_page.dart';
|
||||
import 'package:novyronst/pages/play/pages/play_page.dart';
|
||||
import 'package:novyronst/root/lib_export.dart';
|
||||
import 'package:novyronst/tools/widgets/extend_widget.dart';
|
||||
import 'package:novyronst/tools/widgets/novy_com_widget.dart';
|
||||
import 'package:novyronst/tools/widgets/novy_keep_alive.dart';
|
||||
|
||||
class RootPage extends StatefulWidget {
|
||||
const RootPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _RootPageState();
|
||||
}
|
||||
}
|
||||
|
||||
class _RootPageState extends State<RootPage> {
|
||||
|
||||
final _pageController = PageController();
|
||||
final List<Widget> _pages = [
|
||||
NovyKeepAlive(child: FirstPage()),
|
||||
NovyKeepAlive(child: PlayPage()),
|
||||
CollectionPage(),
|
||||
NovyKeepAlive(child: MyPage()),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
PageView(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
controller: _pageController,
|
||||
children: _pages,
|
||||
),
|
||||
Positioned(
|
||||
left: 0, right: 0, bottom: 0,
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: AppBottomView(
|
||||
onSelectedIndex: (index) {
|
||||
_pageController.jumpToPage(index);
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 底部tabbar
|
||||
class AppBottomView extends StatefulWidget {
|
||||
const AppBottomView({super.key,
|
||||
required this.onSelectedIndex,
|
||||
});
|
||||
|
||||
final Function(int) onSelectedIndex;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _AppBottomViewState();
|
||||
}
|
||||
}
|
||||
|
||||
class _AppBottomViewState extends State<AppBottomView> {
|
||||
|
||||
final List<String> _unselectedIcons = [
|
||||
ConstImage.btHomeUnsel, ConstImage.btPlayUnsel,
|
||||
ConstImage.btCollectUnsel, ConstImage.btMineUnsel
|
||||
];
|
||||
final List<String> _selectedIcons = [
|
||||
ConstImage.btHomeSel, ConstImage.btPlaySel,
|
||||
ConstImage.btCollectSel, ConstImage.btMineSel
|
||||
];
|
||||
final List<String> _titles = ['Home', 'Play', 'Collect', 'Me'];
|
||||
int _currentIndex = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const double _height = 65;
|
||||
return Container(
|
||||
height: _height,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Stack(
|
||||
children: [
|
||||
HelpImage.asset(ConstImage.appBottom,
|
||||
width: AppScreen.screenWidth-32, height: _height,
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
Positioned.fill(
|
||||
child: Padding(padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: List.generate(_unselectedIcons.length, (index) {
|
||||
return _buildTabItem(_titles[index], index, onTap: () {
|
||||
setState(() {
|
||||
_currentIndex = index;
|
||||
});
|
||||
widget.onSelectedIndex(index);
|
||||
|
||||
});
|
||||
}),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabItem(String title, int index, {required Function() onTap}) {
|
||||
String icon = _currentIndex == index ? _selectedIcons[index] : _unselectedIcons[index];
|
||||
Color tcolor = _currentIndex == index ? ConstColor.btGreen : ConstColor.btWhite;
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 7),
|
||||
width: 60, height: 70,
|
||||
child: Column(
|
||||
children: [
|
||||
HelpImage.asset(icon, width: 32, height: 32),
|
||||
const SizedBox(height: 2),
|
||||
NovyText(title, fontSize: 11,
|
||||
color: tcolor,
|
||||
)
|
||||
],
|
||||
)
|
||||
).addInkWell(onTap: onTap);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
/// AppScreen class
|
||||
class AppScreen {
|
||||
static double get screenWidth => _viewSize.width;
|
||||
static double get screenHeight => _viewSize.height;
|
||||
// static double get screenWidth => MediaQuery.of(Get.context!).size.width;
|
||||
// static double get screenHeight => MediaQuery.of(Get.context!).size.height;
|
||||
|
||||
static Size size(BuildContext context) {
|
||||
return MediaQuery.of(context).size;
|
||||
}
|
||||
|
||||
static bool get isDebug => kDebugMode;
|
||||
|
||||
static double get statusBarHeight => Get.statusBarHeight / Get.pixelRatio;
|
||||
|
||||
static double get bottomBarHeight => Get.bottomBarHeight / Get.pixelRatio;
|
||||
|
||||
// static double get tabBarHeight => kToolbarHeight;
|
||||
|
||||
static double get navBarHeight => kToolbarHeight + statusBarHeight;
|
||||
|
||||
static bool get isDark => Get.isDarkMode;
|
||||
|
||||
static bool get isAndroid {
|
||||
return GetPlatform.isAndroid;
|
||||
}
|
||||
|
||||
static bool get isIos {
|
||||
return GetPlatform.isIOS;
|
||||
}
|
||||
|
||||
static Size get _viewSize {
|
||||
if (Get.context != null) {
|
||||
return MediaQuery.of(Get.context!).size;
|
||||
}
|
||||
|
||||
final view = WidgetsBinding.instance.platformDispatcher.views.first;
|
||||
return view.physicalSize / view.devicePixelRatio;
|
||||
}
|
||||
|
||||
static double aRatioWidth({double? h, double aspectRatio = 1}) {
|
||||
h ??= screenHeight;
|
||||
return screenHeight * 1 / aspectRatio;
|
||||
}
|
||||
|
||||
static double get keyboardHeight => Get.mediaQuery.viewInsets.bottom;
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
extension ExtendWidget on Widget {
|
||||
|
||||
Widget addContainer({
|
||||
Color? color,
|
||||
double? height,
|
||||
double? width,
|
||||
EdgeInsets? margin,
|
||||
EdgeInsets? padding,
|
||||
double? radius,
|
||||
BorderRadius? borderRadius,
|
||||
Border? border,
|
||||
GestureTapCallback? onTap,
|
||||
AlignmentGeometry? alignment,
|
||||
Gradient? gradient,
|
||||
List<BoxShadow>? boxShadow,
|
||||
BoxConstraints? constraints,
|
||||
Matrix4? transform,
|
||||
Clip clipBehavior = Clip.none,
|
||||
DecorationImage? image,
|
||||
BlendMode? backgroundBlendMode,
|
||||
BoxShape shape = BoxShape.rectangle,
|
||||
double? minWidth,
|
||||
double? maxWidth,
|
||||
double? minHeight,
|
||||
double? maxHeight,
|
||||
|
||||
/// 打印 widget size 只在 debug 有效
|
||||
bool isPrintSize = false,
|
||||
}) {
|
||||
return Container(
|
||||
width: width,
|
||||
height: height,
|
||||
margin: margin,
|
||||
padding: padding,
|
||||
alignment: alignment,
|
||||
clipBehavior: clipBehavior,
|
||||
constraints:
|
||||
constraints ??
|
||||
BoxConstraints(
|
||||
minWidth: minWidth ?? 0.0,
|
||||
maxWidth: maxWidth ?? double.infinity,
|
||||
minHeight: minHeight ?? 0.0,
|
||||
maxHeight: maxHeight ?? double.infinity,
|
||||
),
|
||||
transform: transform,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
boxShadow: boxShadow,
|
||||
backgroundBlendMode: backgroundBlendMode,
|
||||
shape: shape,
|
||||
image: image,
|
||||
gradient: gradient,
|
||||
border: border,
|
||||
borderRadius: radius != null
|
||||
? BorderRadius.circular(radius)
|
||||
: borderRadius,
|
||||
),
|
||||
child: this,
|
||||
).addInkWell(onTap: onTap);
|
||||
}
|
||||
|
||||
Widget addPadding({EdgeInsets? padding}) {
|
||||
return Padding(padding: padding ?? EdgeInsets.zero, child: this);
|
||||
}
|
||||
|
||||
/// 在当前Widget外层添加一个Align
|
||||
///
|
||||
/// 通过此方法可以设置控件的对齐方式
|
||||
Widget addAlign({AlignmentGeometry alignment = Alignment.centerLeft}) {
|
||||
return Align(alignment: alignment, child: this);
|
||||
}
|
||||
|
||||
Widget addCenter() {
|
||||
return Center(child: this);
|
||||
}
|
||||
|
||||
/// 在当前Widget外层添加一个GestureDetector
|
||||
///
|
||||
/// 通过此方法可以为控件添加点击事件处理函数
|
||||
Widget addGestureDetector({
|
||||
GestureTapCallback? onTap,
|
||||
GestureTapCallback? onDoubleTap,
|
||||
GestureLongPressCallback? onLongPress,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
onDoubleTap: onDoubleTap,
|
||||
onLongPress: onLongPress,
|
||||
child: this,
|
||||
);
|
||||
// return GestureDetectorDebounced(
|
||||
// onTap: onTap,
|
||||
// child: this,
|
||||
// );
|
||||
}
|
||||
|
||||
/// 在当前Widget外层添加一个Visibility
|
||||
///
|
||||
/// 通过此方法可以控制控件的显示和隐藏
|
||||
Widget addVisibility({bool visible = true}) {
|
||||
return Visibility(visible: visible, child: this);
|
||||
}
|
||||
|
||||
|
||||
/// 在当前Widget外层添加一个InkWell
|
||||
///
|
||||
/// 通过此方法可以为控件添加点击事件处理函数
|
||||
Widget addInkWell({GestureTapCallback? onTap}) {
|
||||
if (onTap == null) {
|
||||
return this;
|
||||
}
|
||||
return InkWell(onTap: onTap, child: this);
|
||||
}
|
||||
|
||||
/// 在当前Widget外层添加一个SizedBox
|
||||
///
|
||||
/// 通过此方法可以设置控件的宽高
|
||||
Widget addSize({double? width, double? height}) {
|
||||
return SizedBox(width: width, height: height, child: this);
|
||||
}
|
||||
|
||||
/// 在当前Widget外层添加一个Opacity
|
||||
///
|
||||
/// 通过此方法可以设置控件的透明度
|
||||
Widget addOpacity({double opacity = 1}) {
|
||||
return Opacity(opacity: opacity, child: this);
|
||||
}
|
||||
}
|
||||
|
||||
extension OnRenderObjectWidget on RenderObjectWidget {
|
||||
SliverPadding addPaddingSliver({EdgeInsets? padding}) {
|
||||
return SliverPadding(padding: padding ?? EdgeInsets.zero, sliver: this);
|
||||
}
|
||||
|
||||
DecoratedSliver addDecoratedSliver({
|
||||
Color? color,
|
||||
BorderRadius? borderRadius,
|
||||
Border? border,
|
||||
BoxShape? shape,
|
||||
Gradient? gradient,
|
||||
List<BoxShadow>? boxShadow,
|
||||
EdgeInsets? padding,
|
||||
}) {
|
||||
return DecoratedSliver(
|
||||
decoration: BoxDecoration(
|
||||
color: color ?? Colors.white,
|
||||
border: border,
|
||||
borderRadius: borderRadius,
|
||||
boxShadow: boxShadow,
|
||||
gradient: gradient,
|
||||
shape: shape ?? BoxShape.rectangle,
|
||||
),
|
||||
sliver: addPaddingSliver(padding: padding),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:novyronst/common/const/const_color.dart';
|
||||
import 'package:novyronst/common/help/app_nav.dart';
|
||||
|
||||
import 'extend_widget.dart';
|
||||
|
||||
|
||||
class NovyText extends StatelessWidget {
|
||||
const NovyText( this.text, {
|
||||
super.key,
|
||||
this.color = Colors.white,
|
||||
this.fontSize = 14,
|
||||
this.shadow,
|
||||
this.decoration,
|
||||
this.decorationColor,
|
||||
this.textAlign,
|
||||
this.fontWeight,
|
||||
this.maxLines,
|
||||
this.lineHeight,
|
||||
this.letterSpacing,
|
||||
this.overflow = TextOverflow.ellipsis,
|
||||
this.softWrap,
|
||||
this.fontFamily,
|
||||
});
|
||||
|
||||
|
||||
final String text;
|
||||
final Color? color;
|
||||
final double? fontSize;
|
||||
final TextDecoration? decoration;
|
||||
final Color? decorationColor;
|
||||
final TextAlign? textAlign;
|
||||
final FontWeight? fontWeight;
|
||||
final int? maxLines;
|
||||
final Shadow? shadow;
|
||||
final double? lineHeight;
|
||||
final double? letterSpacing;
|
||||
final TextOverflow? overflow;
|
||||
final bool? softWrap;
|
||||
final String? fontFamily;
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final FontWeight resolvedWeight = fontWeight ?? FontWeight.normal;
|
||||
|
||||
return Text(text, style: TextStyle(
|
||||
fontSize: fontSize,
|
||||
fontWeight: resolvedWeight,
|
||||
decoration: decoration,
|
||||
fontFamily: fontFamily ?? 'Inter',
|
||||
color: color,
|
||||
shadows: shadow == null ? null : [shadow!],
|
||||
decorationColor: decorationColor,
|
||||
height: lineHeight,
|
||||
letterSpacing: letterSpacing,
|
||||
), maxLines: maxLines,
|
||||
overflow: overflow,
|
||||
softWrap: softWrap,
|
||||
textAlign: textAlign,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ComConfirmWidget extends StatelessWidget {
|
||||
|
||||
final String? title;
|
||||
final String? content;
|
||||
final Widget? contentWidget;
|
||||
final String? cancelStr, confirmStr;
|
||||
final double? height;
|
||||
final Function? onConfirmed;
|
||||
final Function? onCanceled;
|
||||
final bool? showCancel;
|
||||
final bool? clickHideAlert;
|
||||
|
||||
const ComConfirmWidget({
|
||||
super.key,
|
||||
this.title,
|
||||
this.content,
|
||||
this.contentWidget,
|
||||
this.cancelStr,
|
||||
this.confirmStr,
|
||||
this.height,
|
||||
this.onConfirmed,
|
||||
this.onCanceled,
|
||||
this.showCancel = true,
|
||||
this.clickHideAlert = true,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: height ?? 160,
|
||||
margin: EdgeInsets.only(left: 25, right: 25),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Column(
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const SizedBox(height: 15,),
|
||||
|
||||
title==null ? SizedBox() : Padding(padding: EdgeInsets.only(left:15, right: 15, bottom: 5),
|
||||
child: NovyText(title!, fontSize: 16, color: Colors.black,
|
||||
)
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Expanded(
|
||||
child: Padding(padding: EdgeInsets.only(left:14, right: 14),
|
||||
child: contentWidget ?? Center(
|
||||
child: NovyText(content!,
|
||||
fontSize: 15, color: ConstColor.themeColor,
|
||||
maxLines: 3),
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
const SizedBox(height: 10),
|
||||
Divider(thickness: 0.6, height: 1),
|
||||
SizedBox(
|
||||
height: 44,
|
||||
child: IntrinsicHeight(
|
||||
child: showCancel! ? Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
|
||||
TextButton(onPressed: () {
|
||||
Navigator.pop(context);
|
||||
onCanceled?.call();
|
||||
},
|
||||
child: Center(
|
||||
child: NovyText(cancelStr ?? 'Cancel',
|
||||
color: Colors.grey, fontSize: 14))
|
||||
),
|
||||
|
||||
VerticalDivider(width: 5, thickness: 0.6,),
|
||||
|
||||
TextButton(onPressed: () {
|
||||
|
||||
if (clickHideAlert == true) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
onConfirmed?.call();
|
||||
},
|
||||
child: Center(
|
||||
child:NovyText(confirmStr ?? 'Confirm',
|
||||
color: ConstColor.themeColor, fontSize: 14))
|
||||
),
|
||||
],
|
||||
) : TextButton(onPressed: () {
|
||||
|
||||
Navigator.pop(context);
|
||||
onConfirmed?.call();
|
||||
},
|
||||
child: Center(
|
||||
child:NovyText(confirmStr ?? 'Confirm',
|
||||
color: ConstColor.themeColor, fontSize: 14,))
|
||||
),
|
||||
)
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ComSheetWidget extends StatelessWidget {
|
||||
|
||||
final Function(int)? onSelected;
|
||||
final String? title;
|
||||
final List<String> items;
|
||||
final TextAlign? textAlign;
|
||||
|
||||
const ComSheetWidget({super.key,
|
||||
this.onSelected,
|
||||
this.title,
|
||||
this.textAlign = TextAlign.left,
|
||||
required this.items,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(child: _mainView());
|
||||
}
|
||||
|
||||
_mainView() {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
height: items.length>5 ? 360 : 40+items.length*47 + 50,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
topRight: Radius.circular(20)
|
||||
),
|
||||
),
|
||||
child: _ifElseWidget(),
|
||||
);
|
||||
}
|
||||
|
||||
_ifElseWidget() {
|
||||
if (title != null) {
|
||||
return Column(
|
||||
children: [
|
||||
const SizedBox(height: 6),
|
||||
Text('$title', style: TextStyle(
|
||||
color: Colors.black, fontSize: 16
|
||||
)),
|
||||
const SizedBox(height: 5),
|
||||
const Divider(height: 8, thickness: 0.6,),
|
||||
// Divider(),
|
||||
const SizedBox(height: 5),
|
||||
Expanded(child: ListView.separated(itemBuilder: (context, index) {
|
||||
return _itemCreateer(index);
|
||||
|
||||
}, separatorBuilder: (context, index) {
|
||||
return Divider( indent: 15, endIndent: 15, thickness: 0.6,);
|
||||
}, itemCount: items.length))
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return ListView.separated(itemBuilder: (context, index) {
|
||||
return _itemCreateer(index);
|
||||
|
||||
}, separatorBuilder: (context, index) {
|
||||
return Divider(indent: 15, endIndent: 15, thickness: 0.6,);
|
||||
}, itemCount: items.length);
|
||||
}
|
||||
}
|
||||
|
||||
_itemCreateer(int index) {
|
||||
return SizedBox(
|
||||
height: 47,
|
||||
child: Center(
|
||||
child: Text(items[index], style: TextStyle(
|
||||
fontSize: 15, color: Colors.black,
|
||||
)),
|
||||
).addInkWell(
|
||||
onTap: () {
|
||||
|
||||
AppNav.back();
|
||||
onSelected?.call(index);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// keep alive
|
||||
class NovyKeepAlive extends StatefulWidget {
|
||||
final Widget child;
|
||||
final bool? wantKeepAlive;
|
||||
|
||||
const NovyKeepAlive(
|
||||
{super.key, required this.child, this.wantKeepAlive = true});
|
||||
|
||||
@override
|
||||
State<NovyKeepAlive> createState() => _CmKeepAlivePageState();
|
||||
}
|
||||
|
||||
class _CmKeepAlivePageState extends State<NovyKeepAlive>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return widget.child;
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => widget.wantKeepAlive!;
|
||||
}
|
||||
Reference in new issue
Block a user