
main.dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import 'package:flutter/material.dart'; import './com/first/firsTest.dart'; void main() => runApp(new MyApp()); class MyApp extends StatelessWidget{ @override Widget build(BuildContext context) { // TODO: implement build return MaterialApp( debugShowCheckedModeBanner: false, title: "My First App", home: Scaffold( appBar: AppBar(title: Text("My Flutter"),), body: firstTest() ), ); } } |
firsttest.dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import 'dart:math'; import 'package:flutter/material.dart'; class firstTest extends StatelessWidget{ @override Widget build(BuildContext context) { return Material( color: Colors.blue, child: Center(child: Text( generate(), textDirection: TextDirection.ltr, style: TextStyle(color: Colors.deepOrangeAccent, fontSize: 40.0), ) ), ); } String generate(){ var random=Random(); int luckynumber=random.nextInt(20); return "My lucky number ${luckynumber}"; } } |