This commit is contained in:
toly
2023-12-27 00:55:04 +08:00
parent 34d8e6dd75
commit 1aeab4fa64
189 changed files with 85 additions and 8676 deletions

View File

@@ -0,0 +1,28 @@
import 'package:flutter/material.dart';
import 'app_navigation.dart';
import 'app_tool_bar.dart';
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
appBarTheme: const AppBarTheme(
elevation: 0,
iconTheme: IconThemeData(color: Colors.black),
titleTextStyle: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.bold,
))),
debugShowCheckedModeBanner: false,
home: const Scaffold(
appBar: AppToolBar(),
body: AppNavigation(),
));
}
}

View File

@@ -0,0 +1,50 @@
import 'package:flutter/material.dart';
import '../page_a.dart';
import '../page_b.dart';
import '../page_c.dart';
import '../home_page.dart';
ValueNotifier<List<String>> router = ValueNotifier(['/']);
class AppNavigation extends StatefulWidget {
const AppNavigation({super.key});
@override
State<AppNavigation> createState() => _AppNavigationState();
}
class _AppNavigationState extends State<AppNavigation> {
@override
void dispose() {
router.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: router,
builder: (_, List<String> value, __) => buildNavigatorByConfig(value),
);
}
final Map<String, Page> _pageMap = const {
'/': MaterialPage(child: HomePage()),
'a': MaterialPage(child: PageA()),
'b': MaterialPage(child: PageB()),
'c': MaterialPage(child: PageC()),
};
Widget buildNavigatorByConfig(List<String> value) {
return Navigator(
onPopPage: _onPopPage,
pages: router.value.map((e) => _pageMap[e]!).toList(),
);
}
bool _onPopPage(Route route, result) {
return route.didPop(result);
}
}

View File

@@ -0,0 +1,64 @@
import 'package:flutter/material.dart';
import 'app_navigation.dart';
class AppToolBar extends StatefulWidget implements PreferredSizeWidget{
const AppToolBar({super.key});
@override
State<AppToolBar> createState() => _AppToolBarState();
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}
class _AppToolBarState extends State<AppToolBar> {
TextEditingController _ctrl = TextEditingController();
@override
void initState() {
super.initState();
_changRoute();
router.addListener(_changRoute);
}
@override
void dispose() {
router.removeListener(_changRoute);
_ctrl.dispose();
super.dispose();
}
void _changRoute() {
_ctrl.text=router.value.join(',');
}
@override
Widget build(BuildContext context) {
return AppBar(
backgroundColor: Colors.white,
elevation: 0,
title : TextField(
controller: _ctrl,
onSubmitted: _onSubmitted,
decoration: InputDecoration( //装饰
filled: true, //填充
fillColor: Color(0xffF3F6F9), //填充颜色
constraints: BoxConstraints(maxHeight: 34), //约束信息
contentPadding: EdgeInsets.only(top: -14,left: 10),
border: UnderlineInputBorder( //边线信息
borderSide: BorderSide.none,
borderRadius: BorderRadius.all(Radius.circular(6)),
),
hintText: "请输入路由", //提示字
hintStyle: TextStyle(fontSize: 14) //提示字样式
),
),
);
}
void _onSubmitted(String value) {
router.value = value.split(',');
}
}

View File

@@ -1,102 +0,0 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
class ColorAddPage extends StatefulWidget {
const ColorAddPage({super.key});
@override
State<ColorAddPage> createState() => _ColorAddPageState();
}
class _ColorAddPageState extends State<ColorAddPage> {
late Color _color;
@override
void initState() {
super.initState();
_color = randomColor;
}
@override
Widget build(BuildContext context) {
String text = '# ${_color.value.toRadixString(16)}';
return Scaffold(
bottomNavigationBar: Container(
margin: EdgeInsets.only(right:20,bottom: 20),
// color: Colors.redAccent,
child: Row(
textDirection:TextDirection.rtl,
children: [
ElevatedButton(onPressed: (){
Navigator.of(context).pop(_color);
}, child: Text('添加')),
SizedBox(width: 12,),
OutlinedButton(onPressed: (){
Navigator.of(context).pop();
}, child: Text('取消')),
],
),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
children: [
Expanded(child: Text(text,style: TextStyle(color: _color,fontSize: 24,letterSpacing: 4),)),
Container(
margin: EdgeInsets.only(left: 10),
width: 40,
height: 40,
child: Icon(
Icons.sell_outlined,
color: Colors.white,
),
decoration: BoxDecoration(
color: _color,
borderRadius: BorderRadius.circular(8),
),
),
],
),
),
ColorPicker(
colorPickerWidth:200,
// enableAlpha: false,
displayThumbColor:true,
pickerColor: _color,
paletteType: PaletteType.hueWheel,
onColorChanged: changeColor,
),
],
),
);
}
Random _random = Random();
Color get randomColor {
return Color.fromARGB(
255,
_random.nextInt(256),
_random.nextInt(256),
_random.nextInt(256),
);
}
void _selectColor() {
Navigator.of(context).pop(_color);
}
void changeColor(Color value) {
_color = value;
setState(() {
});
}
}

View File

@@ -1,48 +0,0 @@
import 'package:flutter/material.dart';
import 'package:iroute/common/components/colors_panel.dart';
import '../../app/navigation/app_router_delegate.dart';
class ColorPage extends StatefulWidget {
const ColorPage({super.key});
@override
State<ColorPage> createState() => _ColorPageState();
}
class _ColorPageState extends State<ColorPage> {
final List<Color> _colors = [
Colors.red, Colors.black, Colors.blue, Colors.green, Colors.orange,
Colors.pink, Colors.purple, Colors.indigo, Colors.amber, Colors.cyan,
Colors.redAccent, Colors.grey, Colors.blueAccent, Colors.greenAccent, Colors.orangeAccent,
Colors.pinkAccent, Colors.purpleAccent, Colors.indigoAccent, Colors.amberAccent, Colors.cyanAccent,
];
@override
Widget build(BuildContext context) {
return Scaffold(
// appBar: AppBar(title:const Text('颜色主页')),
floatingActionButton: FloatingActionButton(
onPressed: _toAddPage,
child: const Icon(Icons.add),
),
body: ColorsPanel(
colors: _colors,
onSelect: _selectColor,
),
);
}
void _selectColor(Color color){
String value = color.value.toRadixString(16);
router.path = '/color/detail?color=$value';
}
void _toAddPage() async {
Color? color = await router.changePathForResult('/color/add');
if (color != null) {
setState(() {
_colors.add(color);
});
}
}
}

View File

@@ -1,43 +0,0 @@
import 'package:flutter/material.dart';
class CounterPage extends StatefulWidget {
const CounterPage({super.key});
@override
State<CounterPage> createState() => _CounterPageState();
}
class _CounterPageState extends State<CounterPage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
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),
),
);
}
}

View File

@@ -1,30 +0,0 @@
import 'package:flutter/material.dart';
class EmptyPage extends StatelessWidget {
const EmptyPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('界面走丢了'),
),
body: Scaffold(
body: Center(
child: Wrap(
spacing: 16,
crossAxisAlignment: WrapCrossAlignment.center,
direction: Axis.vertical,
children: [
Icon(Icons.nearby_error,size: 64, color: Colors.grey),
Text(
'404 界面丢失',
style: TextStyle(fontSize: 24, color: Colors.grey),
),
],
),
),
),
);
}
}

View File

@@ -0,0 +1,29 @@
import 'package:flutter/material.dart';
import 'app/app_navigation.dart';
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
const Color bgColor = Color(0xffCCFFCC);
return Scaffold(
backgroundColor: bgColor,
appBar: AppBar(
title: const Text('主页起点'),
backgroundColor: bgColor,
),
body: Center(child: ElevatedButton(
onPressed: () => toPageA(context),
child: const Text('Push A'),
),
));
}
void toPageA(BuildContext context) {
router.value = ['/', 'a'];
}
}

View File

@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'app/app_navigation.dart';
class PageA extends StatelessWidget {
const PageA({super.key});
@override
Widget build(BuildContext context) {
const Color bgColor = Color(0xffCCFFFF);
return Scaffold(
backgroundColor: bgColor,
appBar: AppBar(
title: const Text('A 界面'),
backgroundColor: bgColor,
leading: BackButton(onPressed: _pop),
),
body: Center(
child: ElevatedButton(
onPressed: () => toPageB(context),
child: const Text('Push B'),
),
));
}
void toPageB(BuildContext context) {
router.value = ['/', 'a', 'b'];
}
void _pop() {
router.value = List.of(router.value)..removeLast();
}
}

View File

@@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
import 'app/app_navigation.dart';
class PageB extends StatelessWidget {
const PageB({super.key});
@override
Widget build(BuildContext context) {
const Color bgColor = Color(0xffCCE5FF);
return Scaffold(
backgroundColor: bgColor,
appBar: AppBar(
title: const Text('B 界面'),
backgroundColor: bgColor,
leading: BackButton(
onPressed: _pop,
),
),
body: Center(
child: ElevatedButton(
onPressed: () => toPageC(context),
child: const Text('Push C'),
),
));
}
void toPageC(BuildContext context){
router.value = ['/','a','b','c'];
}
void _pop() {
router.value = List.of(router.value)..removeLast();
}
}

View File

@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'app/app_navigation.dart';
class PageC extends StatelessWidget {
const PageC({super.key});
@override
Widget build(BuildContext context) {
const Color bgColor = Color(0xffFFE6CC);
return Scaffold(
backgroundColor: bgColor,
appBar: AppBar(
title: const Text('C 界面'),
backgroundColor: bgColor,
leading: BackButton(onPressed: _pop),
),
body: Center(
child: Text('到达终点'),
));
}
void _pop() {
router.value = List.of(router.value)..removeLast();
}
}

View File

@@ -1,11 +0,0 @@
import 'package:flutter/material.dart';
class SettingPage extends StatelessWidget {
const SettingPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body:Center(child: Text('SettingPage')));
}
}

View File

@@ -1,11 +0,0 @@
import 'package:flutter/material.dart';
class UserPage extends StatelessWidget {
const UserPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body:Center(child: Text('UserPage')));
}
}