💄 Optimize styling

This commit is contained in:
2025-09-13 01:20:09 +08:00
parent 4cf035f2f1
commit a9a1680f5d
4 changed files with 163 additions and 71 deletions

View File

@@ -1,20 +1,28 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:latext/latext.dart';
import 'package:simple_math_calc/models/calculation_step.dart';
import 'package:simple_math_calc/solver_service.dart';
import 'package:simple_math_calc/solver.dart';
import 'dart:math';
void main() async {
runApp(const MyApp());
runApp(const CalcApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
class CalcApp extends StatelessWidget {
const CalcApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: '方程计算器',
theme: ThemeData(primarySwatch: Colors.blue, useMaterial3: true),
theme: ThemeData(
primarySwatch: Colors.blue,
useMaterial3: true,
textTheme: GoogleFonts.notoSerifScTextTheme(
Theme.of(context).textTheme, // Inherit existing text theme
),
),
home: const CalculatorHomePage(),
);
}
@@ -68,32 +76,41 @@ class _CalculatorHomePageState extends State<CalculatorHomePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('方程与表达式计算器')),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
TextField(
controller: _controller,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: '输入方程或表达式',
hintText: '例如: 2x^2 - 8x + 6 = 0',
),
onSubmitted: (_) => _solveEquation(),
body: Column(
children: [
Padding(
padding: const EdgeInsets.only(left: 16.0, right: 16.0, top: 16.0),
child: Row(
spacing: 8,
children: [
Expanded(
child: TextField(
controller: _controller,
textAlign: TextAlign.center,
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText: '输入方程或表达式',
floatingLabelAlignment: FloatingLabelAlignment.center,
hintText: '例如: 2x^2 - 8x + 6 = 0',
),
onSubmitted: (_) => _solveEquation(),
),
),
IconButton(
onPressed: _solveEquation,
icon: Icon(Icons.play_arrow),
),
],
),
const SizedBox(height: 16),
ElevatedButton(onPressed: _solveEquation, child: const Text('计算')),
const SizedBox(height: 16),
const Divider(),
Expanded(
child: _isLoading
? const Center(child: CircularProgressIndicator())
: _result == null
? const Center(child: Text('请输入方程开始计算'))
: buildResultView(_result!),
),
],
),
),
Expanded(
child: _isLoading
? const Center(child: CircularProgressIndicator())
: _result == null
? const Center(child: Text('请输入方程开始计算'))
: buildResultView(_result!),
),
],
),
);
}
@@ -101,23 +118,66 @@ class _CalculatorHomePageState extends State<CalculatorHomePage> {
// 构建结果展示视图
Widget buildResultView(CalculationResult result) {
return ListView(
padding: EdgeInsets.only(
left: 16,
right: 16,
bottom: MediaQuery.of(context).padding.bottom + 16,
top: 16,
),
children: [
...result.steps.map(
(step) => Card(
margin: const EdgeInsets.symmetric(vertical: 8),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(8)),
child: Stack(
children: [
Text(
step.title,
style: Theme.of(context).textTheme.titleMedium,
Padding(
padding: const EdgeInsets.only(
left: 12,
right: 12,
bottom: 4,
top: 16,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
step.title,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 4),
SelectableText(step.explanation),
Center(
child: LaTexT(
laTeXCode: Text(
step.formula,
style: Theme.of(context).textTheme.titleMedium,
),
),
),
],
),
),
Positioned(
left: -8,
top: -8,
child: Transform.rotate(
angle: pi / -5,
child: Opacity(
opacity: 0.8,
child: Badge(
backgroundColor: Theme.of(
context,
).colorScheme.primary,
label: Text(
step.stepNumber.toString(),
style: TextStyle(fontSize: 32),
),
),
),
),
),
const SizedBox(height: 4),
SelectableText(step.explanation),
const SizedBox(height: 8),
Center(child: LaTexT(laTeXCode: Text(step.formula))),
],
),
),
@@ -127,17 +187,24 @@ class _CalculatorHomePageState extends State<CalculatorHomePage> {
Card(
color: Theme.of(context).colorScheme.primaryContainer,
child: Padding(
padding: const EdgeInsets.all(16.0),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Column(
children: [
const SizedBox(height: 16),
Text(
"最终答案:",
"最终答案",
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Theme.of(context).colorScheme.onPrimaryContainer,
),
),
const SizedBox(height: 8),
LaTexT(laTeXCode: Text(result.finalAnswer)),
LaTexT(
laTeXCode: Text(
result.finalAnswer,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onPrimaryContainer,
),
),
),
],
),
),